Contents
Tables, Views and Sequences
The table and view modules define six classes, DbClass derived from DbSchemaObject, classes Sequence, Table and View derived from DbClass, MaterializedView derived from View, and ClassDict, derived from DbObjectDict.
Database Class
Class DbClass is derived from ~pyrseas.dbobject.DbSchemaObject and represents a table, view or sequence as defined in the Postgres pg_class catalog.
Sequence
Class Sequence is derived from DbClass and represents a sequence generator. Its keylist attributes are the schema name and the sequence name.
The map returned by to_map and expected as argument by ClassDict.from_map has the following structure:
{'sequence seq1': {'cache_value': 1, 'data_type': 'integer', 'increment_by': 1, 'max_value': None, 'min_value': None, 'owner_column': 'c1', 'owner_table': 't1', 'start_value': 1 } }
Table
Class Table is derived from DbClass and represents a database table. Its keylist attributes are the schema name and the table name.
The map returned by to_map and expected as argument by ClassDict.from_map has a structure similar to the following:
{'table t1': {'columns': [ {'c1': {'type': 'integer', 'not_null': True}}, {'c2': {'type': 'text'}}, {'c3': {'type': 'smallint'}}, {'c4': {'type': 'date', 'default': 'now()'}} ], 'description': "this is the comment for table t1", 'primary_key': {'t1_prim_key': {'columns': ['c1', 'c2']} }, 'foreign_keys': {'t1_fgn_key1': {'columns': ['c2', 'c3'], 'references': {'table': 't2', 'columns': ['pc2', 'pc1']} }, 't1_fgn_key2': {'columns': ['c2'], 'references': {'table': 't3', 'columns': ['qc1']} } }, 'unique_constraints': {...}, 'indexes': {...} } }
The values for unique_constraints and indexes follow a pattern similar to primary_key, but there can be more than one such specification.
Class Dictionary
Class ClassDict is derived from ~pyrseas.dbobject.DbObjectDict and represents the collection of tables, views and sequences in a database.
View
Class View is derived from DbClass and represents a database view. Its keylist attributes are the schema name and the view name.
The map returned by to_map and expected as argument by ClassDict.from_map has a structure similar to the following:
{'view v1': {'columns': [{'c1': {'type': 'integer'}}, {'c2': {'type': 'date'}}], 'definition': " SELECT ...;", 'description': "this is the comment for view v1" } }
Materialized View
Class MaterializedView is derived from View and represents a materialized view. Its keylist attributes are the schema name and the view name.