API¶
The main entry point for dbschema is the open() function:
-
dbschema.open(backend, connection=None, log_sql=False, **connect_kwargs)[source]¶ Returns a
Schemainstance.Parameters: - backend – Backend identifier, must be one of
dbschema.backends.BACKEND_NAMES. - connection (DB-API2 connection or None) – If not
None, a already opened database connection. - log_sql – If
TrueSQL statements are logged (default:False). - connect_kwargs – Connection kwargs if not connection is given.
It is an error if both
connectionandconnect_kwargsare given.Returns: A Schemainstance.Raises: dbschema.exceptions.DBSchemaErrorif things went wrong.- backend – Backend identifier, must be one of
Module Constants¶
-
dbschema.BACKEND_MYSQL= 'mysql'¶ Identifier for MySQL databases.
-
dbschema.BACKEND_POSTGRESQL= 'postgresql'¶ Identifier for PostgreSQL databases.
-
dbschema.BACKEND_SQLITE3= 'sqlite3'¶ Identifier for SQLite3 databases.
Exceptions¶
The following exceptions are defined in dbschema.exceptions:
Database Objects¶
The following graph illustrates the class inheritance in this module:
The following representations of database objects are defined in
dbschema.objects:
-
class
dbschema.objects.Node(name, **kwargs)[source]¶ Base class for database objects.
-
name= None¶ The name of the object.
-
description= None¶ The description of the object.
-
oid= None¶ A unique identifier provided by the underlying backend.
-
find(type_cls=None, name=None, parent=None, recurse=True, **kwargs)[source]¶ Yields database objects matching search parameters.
All search parameters are optional. If not parameters are given all database objects are returned.
Parameters: - type_cls (Subclass of
Node) – Find specific types. - name (str) – The name to match.
- parent (Instance of
Node) – The parent of the objects that should be yieled. - kwargs – All other keyword parameters are used to compare with the attributes of the child instances.
- recurse – If
True(the default) recurse into children.
Returns: Iterator of
Nodeinstances.- type_cls (Subclass of
-
-
class
dbschema.objects.Database(name)[source]¶ Central database class.
-
set_connection(connection, **connect_kwargs)[source]¶ Sets the connection to interact with the database.
Parameters: - connection – If not
None, a already opened database connection. :type connection: DB-API2 connection or None - connect_kwargs – Connection kwargs if not connection is given.
It is an error if both
connectionandconnect_kwargsare given.- connection – If not
-
get_default_namespace()[source]¶ Returns the default namespace or None.
Return type: NamespaceorNone
-
get_tables()[source]¶ Yields all tables from default namespace.
Return type: Generator of Tableinstances.
-
get_views()[source]¶ Yields all views from the default namespace.
Return type: Generator of Viewinstances-
-
set_dirty(type_cls, dirty)[source]¶ Marks/unmarks a certain type as dirty.
Parameters: - type_cls – A
Nodesubclass. - dirty (bool) – Wether the type is dirty.
- type_cls – A
-
refresh_types(type_clss)[source]¶ Instructs the backend to refresh certain types.
“type_clss” is a list of
dbschema.objects.Nodeclasses that should be refreshed.
-
-
class
dbschema.objects.Table(name, **kwargs)[source]¶ A table in the database.
-
get_foreign_keys()[source]¶ Yields foreign key definitions.
Return type: Generator of ForeignKeyinstances.
-
get_reverse_foreign_keys()[source]¶ Yields foreign keys pointing to this table.
Return type: Generaotr of ForeignKeyinstances.
-