Types and Domains¶
The dbtype
module defines seven classes, DbType
derived from DbSchemaObject
, BaseType
,
Composite
, Enum
, Domain
and Range
derived from DbType
, and TypeDict
derived from and
DbObjectDict
.
Database Type¶
Class DbType
is derived from
DbSchemaObject
and represents a SQL type or
domain as defined in the Postgres pg_type catalog.
-
class
pyrseas.dbobject.dbtype.
DbType
(name, schema, description, owner, privileges)¶ A user-defined type, such as a composite, domain or enum
Base Type¶
BaseType
is derived from DbType
and represents a Postgres user-defined base type.
The map returned by to_map()
and expected as argument by
TypeDict.from_map()
has the following structure (not all fields
need be present):
{'type t1':
{'alignment': 'double',
'analyze': 'analyze_func',
'category': 'U',
'delimiter': ',',
'input': 'input_func',
'internallength': 'variable',
'output': 'output_func',
'preferred': 'true',
'receive': 'receive_func',
'send': 'send_func',
'storage': 'plain'
'typmod_in': 'typmod_in_func',
'typmod_out': 'typmod_out_func'
}
}
-
class
pyrseas.dbobject.dbtype.
BaseType
(name, schema, description, owner, privileges, input, output, receive=None, send=None, typmod_in=None, typmod_out=None, analyze=None, internallength=1, alignment=None, storage=None, delimiter=', ', category=None, preferred=False, oid=None)¶ A base type
-
BaseType.
to_map
(db, no_owner, no_privs)¶ Convert a type to a YAML-suitable format
Parameters: no_owner – exclude type owner information Returns: dictionary
-
BaseType.
create
(dbversion=None)¶ Return SQL statements to CREATE the base type
Returns: SQL statements
-
BaseType.
drop
()¶ Generate SQL to drop the type (and related functions)
Returns: list of SQL statements
Composite¶
Composite
is derived from DbType
and represents a standalone composite type.
-
class
pyrseas.dbobject.dbtype.
Composite
(name, schema, description, owner, privileges, oid=None)¶ A composite type
-
Composite.
to_map
(db, no_owner, no_privs)¶ Convert a type to a YAML-suitable format
Parameters: no_owner – exclude type owner information Returns: dictionary
-
Composite.
create
(dbversion=None)¶ Return SQL statements to CREATE the composite type
Returns: SQL statements
-
Composite.
alter
(intype)¶ Generate SQL to transform an existing composite type
Parameters: intype – the new composite type Returns: list of SQL statements Compares the type to an input type and generates SQL statements to transform it into the one represented by the input.
Enum¶
Enum
is derived from DbType
and
represents an enumerated type.
-
class
pyrseas.dbobject.dbtype.
Enum
(name, schema, description, owner, privileges, labels, oid=None)¶ An enumerated type definition
-
Enum.
create
(dbversion=None)¶ Return SQL statements to CREATE the enum
Returns: SQL statements
Domain¶
Domain
is derived from DbType
and
represents a domain.
-
class
pyrseas.dbobject.dbtype.
Domain
(name, schema, description, owner, privileges, type, not_null=False, default=None, oid=None)¶ A domain definition
-
Domain.
to_map
(db, no_owner, no_privs)¶ Convert a domain to a YAML-suitable format
Parameters: no_owner – exclude domain owner information Returns: dictionary
-
Domain.
create
(dbversion=None)¶ Return SQL statements to CREATE the domain
Returns: SQL statements
Range¶
Range
is derived from DbType
and
represents a Postgres range type.
-
class
pyrseas.dbobject.dbtype.
Range
(name, schema, description, owner, privileges, subtype, canonical=None, subtype_diff=None, oid=None)¶ A range type definition
-
Range.
to_map
(db, no_owner, no_privs)¶ Convert a range type to a YAML-suitable format
Parameters: no_owner – exclude type owner information Returns: dictionary
-
Range.
create
(dbversion=None)¶ Return SQL statements to CREATE the range
Returns: SQL statements
-
Range.
alter
(intype, no_owner=False)¶ Generate SQL to transform an existing range type
Parameters: intype – the new range type Returns: list of SQL statements Compares the range to an input range and generates SQL statements to transform it into the one represented by the input.
Type Dictionary¶
TypeDict
is derived from
DbObjectDict
. It is a dictionary that
represents the collection of domains and enums in a database.
-
class
pyrseas.dbobject.dbtype.
TypeDict
(dbconn=None)¶ The collection of user-defined types in a database
-
TypeDict.
from_map
(schema, inobjs, newdb)¶ Initialize the dictionary of types by converting the input map
Parameters: - schema – schema owning the types
- inobjs – YAML map defining the schema objects
- newdb – collection of dictionaries defining the database