Skip to content

Latest commit

 

History

History
103 lines (67 loc) · 2.39 KB

constraint.rst

File metadata and controls

103 lines (67 loc) · 2.39 KB

Constraints

pyrseas.dbobject.constraint

The constraint module defines six classes: Constraint derived from DbSchemaObject, classes CheckConstraint, PrimaryKey, ForeignKey and UniqueConstraint derived from Constraint, and ConstraintDict derived from DbObjectDict.

Constraint

Class Constraint is derived from ~pyrseas.dbobject.DbSchemaObject and represents a constraint on a database table. Its keylist attributes are the schema name, the table name and the constraint name.

Constraint

Constraint.key_columns

Constraint.add

Constraint.drop

Constraint.comment

Check Constraint

CheckConstraint is derived from Constraint and represents a CHECK constraint.

CheckConstraint

CheckConstraint.to_map

CheckConstraint.add

CheckConstraint.diff_map

Primary Key

PrimaryKey is derived from Constraint and represents a primary key constraint.

PrimaryKey

PrimaryKey.to_map

Foreign Key

ForeignKey is derived from Constraint and represents a foreign key constraint.

The following shows a foreign key segment of a map returned by to_map and expected as argument by ConstraintDict.diff_map exemplifying various possibilities:

{'t1_fgn_key1':
    {
    'columns': ['c2', 'c3'],
    'on_delete': 'restrict',
    'on_update': 'set null',
    'references':
        {'columns': ['pc2', 'pc1'], 'schema': 's1', 'table': 't2'}
    }
}

ForeignKey

ForeignKey.ref_columns

ForeignKey.to_map

ForeignKey.add

Unique Constraint

UniqueConstraint is derived from Constraint and represents a UNIQUE, non-primary key constraint.

UniqueConstraint

UniqueConstraint.to_map

Constraint Dictionary

Class ConstraintDict is a dictionary derived from ~pyrseas.dbobject.DbObjectDict and represents the collection of constraints in a database.

ConstraintDict

ConstraintDict.from_map

ConstraintDict.diff_map