module: pyrseas.database

The database module defines Database.


A Database is initialized from a ~pyrseas.database.CatDbConnection object (a specialized class derived from ~pyrseas.lib.dbconn.DbConnection). It consists of one or two Dicts. A Dicts object holds various dictionary objects derived from ~pyrseas.dbobject.DbObjectDict, e.g., ~pyrseas.dbobject.schema.SchemaDict, ~pyrseas.dbobject.table.ClassDict, and ~pyrseas.dbobject.column.ColumnDict. The key for each dictionary is a Python tuple (or a single value in the case of SchemaDict). For example, the ~pyrseas.dbobject.table.ClassDict dictionary is indexed by (schema name, table name). In addition, object instances in each dictionary are linked to related objects in other dictionaries, e.g., columns are linked to the tables where they belong.

The db Dicts object --always present-- defines the database schemas, including their tables and other objects, by querying the system catalogs. The ndb Dicts object defines the schemas based on the input_map supplied to the diff_map method.

The to_map method returns and the diff_map method takes as input, a dictionary as shown below. It uses 'schema schema_name' as the key for each schema. The value corresponding to each 'schema schema_name' is another dictionary using 'sequences', 'tables', etc., as keys and more dictionaries as values. For example:

{'schema public':
    {'sequence seq1': { ... },
     'sequence seq2': { ... },
     'table t1': { ... },
     'table t2': { ... },
     'table t3': { ... },
     'view v1': { ... }
 'schema s1': { ... },
 'schema s2': { ... }

Refer to ~pyrseas.dbobject.table.Sequence, ~pyrseas.dbobject.table.Table and ~pyrseas.dbobject.table.View for details on the lower level dictionaries.

autoclass: Database

Methods from_catalog and from_map are for internal use. Methods to_map and diff_map are the external API.

automethod: Database.from_catalog

automethod: Database.from_map

automethod: Database.to_map

automethod: Database.diff_map