The schema module provides the building blocks for database metadata.
This means all the entities within a SQL database that we might want to look at, modify, or create and delete are described by these objects, in a database-agnostic way.
A structure of SchemaItems also provides a visitor interface which is the primary method by which other methods operate upon the schema. The SQL package extends this structure with its own clause-specific objects as well as the visitor interface, so that the schema package plugs in to the SQL package.
Represent a column in a database table.
This is a subclass of sql.ColumnClause and represents an actual existing table in the database, in a similar fashion as TableClause/Table.
Construct a new Column object.
Arguments are:
Keyword arguments include:
A plain default value on a column.
This could correspond to a constant, a callable function, or a SQL clause.
Represent a table-level Constraint such as a composite primary key, foreign key, or unique constraint.
Implements a hybrid of dict/setlike behavior with regards to the list of underying columns.
Defines a column-level ForeignKey constraint between two columns.
ForeignKey is specified as an argument to a Column object.
One or more ForeignKey objects are used within a ForeignKeyConstraint object which represents the table-level constraint definition.
Construct a new ForeignKey object.
Table-level foreign key constraint, represents a collection of ForeignKey objects.
Construct a new ForeignKeyConstraint.
Represent an index of columns from a database table.
Construct an index object.
Arguments are:
Keyword arguments include:
Represent a collection of Tables and their associated schema constructs.
create a new MetaData object.
an Engine or Connection to which this MetaData is bound. this is a settable property as well.
bind this MetaData to an Engine.
DEPRECATED. use metadata.bind = <engine> or metadata.bind = <url>.
Create all tables stored in this metadata.
This will conditionally create tables depending on if they do not yet exist in the database.
Drop all tables stored in this metadata.
This will conditionally drop tables depending on if they currently exist in the database.
A default that takes effect on the database side.
Base class for items that define a database schema.
Return the engine or raise an error if no engine.
Deprecated. use the "bind" attribute.
Represent a sequence, which applies to Oracle and Postgres databases.
Construct a new Sequence.
Represent a relational database table.
This subclasses sql.TableClause to provide a table that is associated with an instance of MetaData, which in turn may be associated with an instance of SQLEngine.
Whereas TableClause represents a table as its used in an SQL expression, Table represents a table as it exists in a database schema.
If this Table is ultimately associated with an engine, the Table gains the ability to access the database directly without the need for dealing with an explicit Connection object; this is known as "implicit execution".
Implicit operation allows the Table to access the database to reflect its own properties (via the autoload=True flag), it allows the create() and drop() methods to be called without passing a connectable, and it also propigates the underlying engine to constructed SQL objects so that they too can be executed via their execute() method without the need for a Connection.
Construct a Table.
Table objects can be constructed directly. The init method is actually called via the TableSingleton metaclass. Arguments are:
The name of this table, exactly as it appears, or will appear, in the database.
This property, along with the schema, indicates the singleton identity of this table.
Further tables constructed with the same name/schema combination will return the same Table instance.
options include:
Issue a CREATE statement for this table.
See also metadata.create_all().
Issue a DROP statement for this table.
See also metadata.drop_all().
Return a copy of this Table associated with a different MetaData.
A MetaData that binds to multiple Engine implementations on a thread-local basis.