Browse files

Add support for base types.

 * docs/function.rst: Add Aggregate.diff_map.
 * docs/operator.rst: Add Operator.qualname.
 * docs/type.rst: Add BaseType documentation.
 * pyrseas/ Add db.functions as argument to call of
 * pyrseas/dbobject/ (split_schema_obj): Renamed from
 * pyrseas/dbobject/ (ConstraintDict._from_catalog):
   Renamed split_schema_table to split_schema_obj.
 * pyrseas/dbobject/ (DbType.diff_map): Moved from Domain to
   be used by all subclasses.  (BaseType): Add class to support new
   functionality.  (Composite.to_map): Output description if present.
   (TypeDict.{query,_from_catalog}): Add new attributes for base
   types.  (TypeDict.from_map): Add handling of base types,
   re-organize others.  (TypeDict.link_refs): Handle base types, add
   dbfunctions argument to link type-related functions.
   (TypeDict._drop): Special case for functions that do not get
   dropped by DROP TYPE ... CASCADE.
 * pyrseas/dbobject/ (Function.to_map): Add mapping of cost
   if present. (Function.create): Add basetype argument, support
   'internal' as a language, add cost if present.
   (Function.diff_map): Test for presence of 'source' attributes
   before comparing them.  (Aggregate.diff_map): Add missing method.
   (ProcDict.{query,_from_catalog}): Retrieve cost.
   (ProcDict.from_map): Use str.partition instead of str.find.
   (ProcDict._drop): Split loop into two, first for Aggregates, then
   rest, but exclude type-related functions.
 * pyrseas/dbobject/ (LanguageDict.from_map): Use
   str.partition instead of str.find.
 * pyrseas/dbobject/ (Operator.create): Add RESTRICT and
   JOIN, generalize handling of optional clauses.
   (OperatorDict.{query,_from_catalog}): Retrieve restrict and join
   functions.  (OperatorDict.from_map): Use str.partition instead of
 * pyrseas/dbobject/ (SchemaDict.from_map): Use str.partition
   instead of str.find.  (SchemaDict.link_refs): Add handling of base
 * pyrseas/dbobject/ Rename split_schema_table to
   split_schema_obj.  (ClassDict.from_map): Use str.partition instead
   of str.find.
 * tests/dbobject/ Add test to generate DROP
 * tests/dbobject/ Minor format change suggested by
 * tests/dbobject/  Add BaseType test cases.
 * tests/dbobject/ (PostgresDb.clear): Drop types, including
   base types, before functions.
  • Loading branch information...
1 parent 56b3295 commit 25d9f69809a5b31a853a8110202d45a66e50bef1 @jmafc jmafc committed Sep 1, 2011
@@ -50,6 +50,8 @@ Aggregate Function
.. automethod:: Aggregate.create
+.. automethod:: Aggregate.diff_map
Procedure Dictionary
@@ -18,6 +18,8 @@ represents a `PostgreSQL user-defined operator
.. automethod:: Operator.extern_key
+.. automethod:: Operator.qualname
.. automethod:: Operator.identifier
.. automethod:: Operator.to_map
@@ -3,10 +3,10 @@ Types and Domains
.. module:: pyrseas.dbobject.dbtype
-The :mod:`dbtype` module defines five classes, :class:`DbType` derived
-from :class:`DbSchemaObject`, :class:`Composite`, :class:`Enum` and
-:class:`Domain` derived from :class:`DbType`, and :class:`TypeDict`
-derived from and :class:`DbObjectDict`.
+The :mod:`dbtype` module defines six classes, :class:`DbType` derived
+from :class:`DbSchemaObject`, :class:`BaseType`, :class:`Composite`,
+:class:`Enum` and :class:`Domain` derived from :class:`DbType`, and
+:class:`TypeDict` derived from and :class:`DbObjectDict`.
Database Type
@@ -18,6 +18,39 @@ enumerated types are implemented currently.
.. autoclass:: DbType
+Base Type
+:class:`BaseType` is derived from :class:`~pyrseas.dbobject.DbType`
+and represents a PostgreSQL `user-defined base type
+The map returned by :meth:`to_map` and expected as argument by
+:meth:`diff_map` has the following structure (not all fields need be
+ {'type t1':
+ {'alignment': 'double',
+ 'analyze': 'analyze_func',
+ 'input': 'input_func',
+ 'internallength': 'variable',
+ 'output': 'output_func',
+ 'receive': 'receive_func',
+ 'send': 'send_func',
+ 'storage': 'plain'
+ 'typmod_in': 'typmod_in_func',
+ 'typmod_out': 'typmod_out_func'
+ }
+ }
+.. autoclass:: BaseType
+.. automethod:: BaseType.to_map
+.. automethod:: BaseType.create
+.. automethod:: BaseType.drop
@@ -75,7 +75,7 @@ def _link_refs(self, db):
db.tables.link_refs(db.columns, db.constraints, db.indexes,
db.rules, db.triggers)
- db.types.link_refs(db.columns, db.constraints)
+ db.types.link_refs(db.columns, db.constraints, db.functions)
def from_catalog(self):
"""Populate the database objects by querying the catalogs
@@ -34,22 +34,23 @@ def quote_id(name):
return regular_id and name or '"%s"' % name
-def split_schema_table(tbl, sch=None):
- """Return a (schema, table) tuple given a possibly schema-qualified name
+def split_schema_obj(obj, sch=None):
+ """Return a (schema, object) tuple given a possibly schema-qualified name
- :param tbl: table name or schema.table
+ :param obj: object name or schema.object
+ :param sch: schema name (defaults to 'public')
:return: tuple
qualsch = sch
if sch == None:
qualsch = 'public'
- if '.' in tbl:
- (qualsch, tbl) = tbl.split('.')
- if tbl[:1] == '"' and tbl[-1:] == '"':
- tbl = tbl[1:-1]
+ if '.' in obj:
+ (qualsch, obj) = obj.split('.')
+ if obj[:1] == '"' and obj[-1:] == '"':
+ obj = obj[1:-1]
if sch != qualsch:
sch = qualsch
- return (sch, tbl)
+ return (sch, obj)
class DbObject(object):
@@ -163,7 +164,7 @@ def qualname(self):
def unqualify(self):
"""Adjust the schema and table name if the latter is qualified"""
if hasattr(self, 'table') and '.' in self.table:
- (sch, self.table) = split_schema_table(self.table, self.schema)
+ (sch, self.table) = split_schema_obj(self.table, self.schema)
def drop(self):
"""Return a SQL DROP statement for the schema object
@@ -9,7 +9,7 @@
derived from DbObjectDict.
from pyrseas.dbobject import DbObjectDict, DbSchemaObject
-from pyrseas.dbobject import quote_id, split_schema_table
+from pyrseas.dbobject import quote_id, split_schema_obj
ACTIONS = {'r': 'restrict', 'c': 'cascade', 'n': 'set null',
@@ -283,7 +283,7 @@ def _from_catalog(self):
constr.on_delete = ACTIONS[constr.on_delete]
reftbl = constr.ref_table
- (constr.ref_schema, constr.ref_table) = split_schema_table(
+ (constr.ref_schema, constr.ref_table) = split_schema_obj(
self[(sch, tbl, cns)] = ForeignKey(**constr.__dict__)
elif constr_type == 'u':
Oops, something went wrong.

0 comments on commit 25d9f69

Please sign in to comment.