Files
Home-AssistantConfig/deps/sqlalchemy/sql/__pycache__/schema.cpython-34.pyc

2007 lines
137 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
|<7C><>W<EFBFBD>@<00>@swdZddlmZddlZddlmZmZmZmZddl m
Z
m Z ddlm Z dd lm Z dd
l mZmZdd lmZmZmZmZmZmZmZmZmZdd lmZddlZddlZdd lmZddlZej d<00>Z!ej dd<00>Z"dd<00>Z#ej$Gdd<00>de
e j%<00><00>Z&Gdd<00>de e&e<00>Z'Gdd<00>de&e<00>Z(Gdd<00>de e&<00>Z)Gdd<00>de*<00>Z+Gdd<00>de+e&<00>Z,Gdd <00>d e,<00>Z-Gd!d"<00>d"e,<00>Z.ej$Gd#d$<00>d$e+e
<00><00>Z/Gd%d&<00>d&e/<00>Z0Gd'd(<00>d(e0<00>Z1Gd)d*<00>d*e e&<00>Z2d+d,<00>Z3d-d.<00>Z4Gd/d0<00>d0e*<00>Z5Gd1d2<00>d2e5e2<00>Z6Gd3d4<00>d4e6<00>Z7Gd5d6<00>d6e6<00>Z8Gd7d8<00>d8e6<00>Z9Gd9d:<00>d:e6<00>Z:Gd;d<<00>d<e e5e&<00>Z;ej<id=d>6<>Z=Gd?d@<00>d@e&<00>Z>GdAdB<00>dBe><00>Z?dS)Ca/The schema module provides the building blocks for database metadata.
Each element within this module describes a database entity which can be
created and dropped, or is otherwise part of such an entity. Examples include
tables, columns, sequences, and indexes.
All entities are subclasses of :class:`~sqlalchemy.schema.SchemaItem`, and as
defined in this module they are intended to be agnostic of any vendor-specific
constructs.
A collection of entities are grouped into a unit called
:class:`~sqlalchemy.schema.MetaData`. MetaData serves as a logical grouping of
schema elements, and can also be associated with an actual database connection
such that operations involving the contained elements can contact the database
as needed.
Two of the elements here also build upon their "syntactic" counterparts, which
are defined in :class:`~sqlalchemy.sql.expression.`, specifically
:class:`~sqlalchemy.schema.Table` and :class:`~sqlalchemy.schema.Column`.
Since these objects are part of the SQL expression language, they are usable
as components in SQL expressions.
<EFBFBD>)<01>absolute_importN<74>)<04>exc<78>util<69>event<6E>
inspection<EFBFBD>)<02>SchemaEventTarget<65> DialectKWArgs)<01>visitors)<01>type_api)<02>_bind_or_error<6F>ColumnCollection) <09> ClauseElement<6E> ColumnClause<73>_truncated_label<65> _as_truncated<65>
TextClause<EFBFBD>_literal_as_text<78> ColumnElement<6E> _find_columns<6E> quoted_name)<01> TableClause)<01>ddlZ retain_schemaZ blank_schemaz<61>Symbol indicating that a :class:`.Table` or :class:`.Sequence`
should have 'None' for its schema, even if the parent
:class:`.MetaData` has specified a schema.
.. versionadded:: 1.0.14
cCs |dkr|S|d|SdS)N<>.<2E>)<02>name<6D>schemarr<00>;/tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/sql/schema.py<70>_get_table_key>s rc@s<>eZdZdZdZdd<00>Zdd<00>Zdd<00>Zd d
<00>Ze e
j d d <00>d d<00><00><00>Z e
j dd<00><00>Zdd<00>ZdS)<14>
SchemaItemz3Base class for items that define a database schema.<2E> schema_itemcCs|j|||<00>S)N)<01>_execute_default)<04>self<6C>
connectionZ multiparams<6D>paramsrrr<00>_execute_on_connectionKsz!SchemaItem._execute_on_connectioncGs1x*|D]"}|dk r|j|<00>qqWdS)z7Initialize the list of child items for this SchemaItem.N)<01>_set_parent_with_dispatch)r#<00>args<67>itemrrr<00> _init_itemsNs  zSchemaItem._init_itemscKsgS)z"used to allow SchemaVisitor accessr)r#<00>kwargsrrr<00> get_childrenUszSchemaItem.get_childrencCstj|ddg<00>S)NZ
omit_kwarg<EFBFBD>info)r<00> generic_repr)r#rrr<00>__repr__YszSchemaItem.__repr__z0.9zUse ``<obj>.name.quote``cCs
|jjS)z<>Return the value of the ``quote`` flag passed
to this schema object, for those schema items which
have a ``name`` field.
)r<00>quote)r#rrrr0\s zSchemaItem.quotecCsiS)aLInfo dictionary associated with the object, allowing user-defined
data to be associated with this :class:`.SchemaItem`.
The dictionary is automatically generated when first accessed.
It can also be specified in the constructor of some objects,
such as :class:`.Table` and :class:`.Column`.
r)r#rrrr-gs
zSchemaItem.infocCs;d|jkr$|jj<00>|_n|jj|j<00>|S)Nr-)<05>__dict__r-<00>copy<70>dispatch<63>_update)r#r!rrr<00>_schema_item_copysszSchemaItem._schema_item_copyN)<10>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__<5F>__visit_name__r&r*r,r/<00>propertyr<00>
deprecatedr0<00>memoized_propertyr-r5rrrrr Es     !
 r cs<>eZdZdZdZdd<00>Zeejdd<00>dd<00><00><00>Z d d
<00>Z
<00>fd d <00>Z fd d<00>Z edd<00><00>Z edd<00><00>Zdd<00>Zdd<00>Zdd<00>Zdd<00>Zejdd<00><00>Zedd<00><00>Zdd <00>Zd!d"<00>Zed#d$<00><00>Zd%d&<00>Zd'd(<00>Zd)d*<00>Zd+d,<00>Zd-d.<00>Zd/d0d1d2<00>Zd3d4d5<00>Zd3d0d6d7<00>Z d3d0d8d9<00>Z!e"d3d3d:d;<00>Z#<00>S)<<3C>Tablea<65>/Represent a table in a database.
e.g.::
mytable = Table("mytable", metadata,
Column('mytable_id', Integer, primary_key=True),
Column('value', String(50))
)
The :class:`.Table` object constructs a unique instance of itself based
on its name and optional schema name within the given
:class:`.MetaData` object. Calling the :class:`.Table`
constructor with the same name and same :class:`.MetaData` argument
a second time will return the *same* :class:`.Table` object - in this way
the :class:`.Table` constructor acts as a registry function.
.. seealso::
:ref:`metadata_describing` - Introduction to database metadata
Constructor arguments are as follows:
:param name: The name of this table as represented in the database.
The table name, along with the value of the ``schema`` parameter,
forms a key which uniquely identifies this :class:`.Table` within
the owning :class:`.MetaData` collection.
Additional calls to :class:`.Table` with the same name, metadata,
and schema name will return the same :class:`.Table` object.
Names which contain no upper case characters
will be treated as case insensitive names, and will not be quoted
unless they are a reserved word or contain special characters.
A name with any number of upper case characters is considered
to be case sensitive, and will be sent as quoted.
To enable unconditional quoting for the table name, specify the flag
``quote=True`` to the constructor, or use the :class:`.quoted_name`
construct to specify the name.
:param metadata: a :class:`.MetaData` object which will contain this
table. The metadata is used as a point of association of this table
with other tables which are referenced via foreign key. It also
may be used to associate this table with a particular
:class:`.Connectable`.
:param \*args: Additional positional arguments are used primarily
to add the list of :class:`.Column` objects contained within this
table. Similar to the style of a CREATE TABLE statement, other
:class:`.SchemaItem` constructs may be added here, including
:class:`.PrimaryKeyConstraint`, and :class:`.ForeignKeyConstraint`.
:param autoload: Defaults to False, unless :paramref:`.Table.autoload_with`
is set in which case it defaults to True; :class:`.Column` objects
for this table should be reflected from the database, possibly
augmenting or replacing existing :class:`.Column` objects that were
expicitly specified.
.. versionchanged:: 1.0.0 setting the :paramref:`.Table.autoload_with`
parameter implies that :paramref:`.Table.autoload` will default
to True.
.. seealso::
:ref:`metadata_reflection_toplevel`
:param autoload_replace: Defaults to ``True``; when using
:paramref:`.Table.autoload`
in conjunction with :paramref:`.Table.extend_existing`, indicates
that :class:`.Column` objects present in the already-existing
:class:`.Table` object should be replaced with columns of the same
name retrieved from the autoload process. When ``False``, columns
already present under existing names will be omitted from the
reflection process.
Note that this setting does not impact :class:`.Column` objects
specified programmatically within the call to :class:`.Table` that
also is autoloading; those :class:`.Column` objects will always
replace existing columns of the same name when
:paramref:`.Table.extend_existing` is ``True``.
.. versionadded:: 0.7.5
.. seealso::
:paramref:`.Table.autoload`
:paramref:`.Table.extend_existing`
:param autoload_with: An :class:`.Engine` or :class:`.Connection` object
with which this :class:`.Table` object will be reflected; when
set to a non-None value, it implies that :paramref:`.Table.autoload`
is ``True``. If left unset, but :paramref:`.Table.autoload` is
explicitly set to ``True``, an autoload operation will attempt to
proceed by locating an :class:`.Engine` or :class:`.Connection` bound
to the underlying :class:`.MetaData` object.
.. seealso::
:paramref:`.Table.autoload`
:param extend_existing: When ``True``, indicates that if this
:class:`.Table` is already present in the given :class:`.MetaData`,
apply further arguments within the constructor to the existing
:class:`.Table`.
If :paramref:`.Table.extend_existing` or
:paramref:`.Table.keep_existing` are not set, and the given name
of the new :class:`.Table` refers to a :class:`.Table` that is
already present in the target :class:`.MetaData` collection, and
this :class:`.Table` specifies additional columns or other constructs
or flags that modify the table's state, an
error is raised. The purpose of these two mutually-exclusive flags
is to specify what action should be taken when a :class:`.Table`
is specified that matches an existing :class:`.Table`, yet specifies
additional constructs.
:paramref:`.Table.extend_existing` will also work in conjunction
with :paramref:`.Table.autoload` to run a new reflection
operation against the database, even if a :class:`.Table`
of the same name is already present in the target
:class:`.MetaData`; newly reflected :class:`.Column` objects
and other options will be added into the state of the
:class:`.Table`, potentially overwriting existing columns
and options of the same name.
.. versionchanged:: 0.7.4 :paramref:`.Table.extend_existing` will
invoke a new reflection operation when combined with
:paramref:`.Table.autoload` set to True.
As is always the case with :paramref:`.Table.autoload`,
:class:`.Column` objects can be specified in the same :class:`.Table`
constructor, which will take precedence. Below, the existing
table ``mytable`` will be augmented with :class:`.Column` objects
both reflected from the database, as well as the given :class:`.Column`
named "y"::
Table("mytable", metadata,
Column('y', Integer),
extend_existing=True,
autoload=True,
autoload_with=engine
)
.. seealso::
:paramref:`.Table.autoload`
:paramref:`.Table.autoload_replace`
:paramref:`.Table.keep_existing`
:param implicit_returning: True by default - indicates that
RETURNING can be used by default to fetch newly inserted primary key
values, for backends which support this. Note that
create_engine() also provides an implicit_returning flag.
:param include_columns: A list of strings indicating a subset of
columns to be loaded via the ``autoload`` operation; table columns who
aren't present in this list will not be represented on the resulting
``Table`` object. Defaults to ``None`` which indicates all columns
should be reflected.
:param info: Optional data dictionary which will be populated into the
:attr:`.SchemaItem.info` attribute of this object.
:param keep_existing: When ``True``, indicates that if this Table
is already present in the given :class:`.MetaData`, ignore
further arguments within the constructor to the existing
:class:`.Table`, and return the :class:`.Table` object as
originally created. This is to allow a function that wishes
to define a new :class:`.Table` on first call, but on
subsequent calls will return the same :class:`.Table`,
without any of the declarations (particularly constraints)
being applied a second time.
If :paramref:`.Table.extend_existing` or
:paramref:`.Table.keep_existing` are not set, and the given name
of the new :class:`.Table` refers to a :class:`.Table` that is
already present in the target :class:`.MetaData` collection, and
this :class:`.Table` specifies additional columns or other constructs
or flags that modify the table's state, an
error is raised. The purpose of these two mutually-exclusive flags
is to specify what action should be taken when a :class:`.Table`
is specified that matches an existing :class:`.Table`, yet specifies
additional constructs.
.. seealso::
:paramref:`.Table.extend_existing`
:param listeners: A list of tuples of the form ``(<eventname>, <fn>)``
which will be passed to :func:`.event.listen` upon construction.
This alternate hook to :func:`.event.listen` allows the establishment
of a listener function specific to this :class:`.Table` before
the "autoload" process begins. Particularly useful for
the :meth:`.DDLEvents.column_reflect` event::
def listen_for_reflect(table, column_info):
"handle the column reflection event"
# ...
t = Table(
'sometable',
autoload=True,
listeners=[
('column_reflect', listen_for_reflect)
])
:param mustexist: When ``True``, indicates that this Table must already
be present in the given :class:`.MetaData` collection, else
an exception is raised.
:param prefixes:
A list of strings to insert after CREATE in the CREATE TABLE
statement. They will be separated by spaces.
:param quote: Force quoting of this table's name on or off, corresponding
to ``True`` or ``False``. When left at its default of ``None``,
the column identifier will be quoted according to whether the name is
case sensitive (identifiers with at least one upper case character are
treated as case sensitive), or if it's a reserved word. This flag
is only needed to force quoting of a reserved word which is not known
by the SQLAlchemy dialect.
:param quote_schema: same as 'quote' but applies to the schema identifier.
:param schema: The schema name for this table, which is required if
the table resides in a schema other than the default selected schema
for the engine's database connection. Defaults to ``None``.
If the owning :class:`.MetaData` of this :class:`.Table` specifies
its own :paramref:`.MetaData.schema` parameter, then that schema
name will be applied to this :class:`.Table` if the schema parameter
here is set to ``None``. To set a blank schema name on a :class:`.Table`
that would otherwise use the schema set on the owning :class:`.MetaData`,
specify the special symbol :attr:`.BLANK_SCHEMA`.
.. versionadded:: 1.0.14 Added the :attr:`.BLANK_SCHEMA` symbol to
allow a :class:`.Table` to have a blank schema name even when the
parent :class:`.MetaData` specifies :paramref:`.MetaData.schema`.
The quoting rules for the schema name are the same as those for the
``name`` parameter, in that quoting is applied for reserved words or
case-sensitive names; to enable unconditional quoting for the
schema name, specify the flag
``quote_schema=True`` to the constructor, or use the
:class:`.quoted_name` construct to specify the name.
:param useexisting: Deprecated. Use :paramref:`.Table.extend_existing`.
:param \**kw: Additional keyword arguments not mentioned above are
dialect specific, and passed in the form ``<dialectname>_<argname>``.
See the documentation regarding an individual dialect at
:ref:`dialect_toplevel` for detail on documented arguments.
<20>tablec Osu|stj|<00>Sy*|d|d|dd<00>}}}Wntk
r]td<00><00>YnX|jdd<00>}|dkr<>|j}n|tkr<>d}n|jdd<00>}|jdd<00>}d |krd
}tj |<00>|r<>d }t
j |<00><00>n|jd d<00>}n|r7|r7d }t
j |<00><00>n|jd d<00>} t ||<00>}
|
|j kr<>| r<>| r<>t|<00>r<>t
jd|
<16><00>n|j |
} |r<>| j||<00>n| S| r<>t
jd|
<16><00>ntj|<00>} | jj| |<00>|j||| <00>y1| j||||<00>| jj| |<00>| SWn+tj<00><00>|j||<00>WdQXYnXdS)Nrrrz$Table() takes at least two argumentsr<00> keep_existingF<67>extend_existingZ useexistingz0useexisting is deprecated. Use extend_existing.z/useexisting is synonymous with extend_existing.z9keep_existing and extend_existing are mutually exclusive.<2E> mustexistz<74>Table '%s' is already defined for this MetaData instance. Specify 'extend_existing=True' to redefine options and columns on an existing Table object.zTable '%s' not defined)<18>object<63>__new__<5F>
IndexError<EFBFBD> TypeError<6F>getr<00> BLANK_SCHEMA<4D>popr<00>warn_deprecatedr<00> ArgumentErrorr<00>tables<65>bool<6F>InvalidRequestError<6F>_init_existingr3Zbefore_parent_attach<63>
_add_table<EFBFBD>_init<69>after_parent_attachZ safe_reraise<73> _remove_table) <0C>clsr(<00>kwr<00>metadatarr@rA<00>msgrB<00>keyr?rrrrD<00>s^ *           z Table.__new__z0.9zUse ``table.schema.quote``cCs
|jjS)z^Return the value of the ``quote_schema`` flag passed
to this :class:`.Table`.
)rr0)r#rrr<00> quote_schema<6D>szTable.quote_schemacOsdS)z<>Constructor for :class:`~.schema.Table`.
This method is a no-op. See the top-level
documentation for :class:`~.schema.Table`
for constructor arguments.
Nr)r#r(rUrrr<00>__init__<5F>szTable.__init__c sEtt|<00>jt||jdd<00><00><00>||_|jdd<00>|_|jdkrg|j|_nB|jtkr<>d|_n'|jdd<00>}t|j|<00>|_t<00>|_ t<00>|_
t <00>|_ t <00>j|<00>t<00>|_t<00>|_|jdk r d|j|jf|_n |j|_|jdd<00>}|jd|dk <00>}|jdd<00>|jd d<00>}|jd
d<00>|_d |kr<>|jd <00>|_nd |kr<>|jd <00>} x*| D]\}
} tj||
| <00>q<>Wn|jd g<00>|_|j|<00>|r4|j|||<00>n|j|<00>dS)Nr0rrYz%s.%s<> autoload_with<74>autoload<61>autoload_replaceT<65>include_columns<6E>implicit_returningr-<00> listeners<72>prefixes)<1B>superr>rZrrIrVrrH<00>set<65>indexes<65> constraintsr<00>_columns<6E>PrimaryKeyConstraintr'<00> foreign_keys<79>_extra_dependenciesr<00>fullnamer_r-r<00>listenZ _prefixes<65> _extra_kwargs<67> _autoloadr*) r#rrVr(r+rYr[r\r^r`<00>evt<76>fn)<01> __class__rrrQ<00>sF           z Table._initcCsW|r%|j|jj|||<00>n.t|dd<00>}|j|jj|||<00>dS)NrWz<>No engine is bound to this Table's MetaData. Pass an engine to the Table via autoload_with=<someengine>, or associate the MetaData with an engine via metadata.bind=<someengine>)<04> run_callable<6C>dialectZ reflecttabler )r#rVr[r^<00>exclude_columns<6E>bindrrrrms   zTable._autoloadcCst|jddd<00><00>S)zTReturn the set of constraints as a list, sorted by creation
order.
rXcSs|jS)N)Z_creation_order)<01>crrr<00><lambda>sz+Table._sorted_constraints.<locals>.<lambda>)<02>sortedre)r#rrr<00>_sorted_constraintsszTable._sorted_constraintscCstdd<00>|jD<><00>S)z<>:class:`.ForeignKeyConstraint` objects referred to by this
:class:`.Table`.
This list is produced from the collection of :class:`.ForeignKey`
objects currently associated.
.. versionadded:: 1.0.0
css|]}|jVqdS)N)<01>
constraint)<02>.0<EFBFBD>fkcrrr<00> <genexpr>,sz0Table.foreign_key_constraints.<locals>.<genexpr>)rcrh)r#rrr<00>foreign_key_constraints!s zTable.foreign_key_constraintsc Os<>|jdd<00>}|jd|dk <00>}|jdd<00>}|jdd<00>}|r<>||jkr<>tjd|j|f<00><00>n|jdd<00>}|dk r<>x6|jD](}|j|kr<>|jj|<00>q<>q<>Wnx,dD]$} | |kr<>tjd
<00><00>q<>q<>Wd |kr(|jd <00>|_n|ro|sMd d <00>|jD<>}
nf}
|j |j
|||
<00>n|j |<00>|j |<00>dS)Nr[r\r]Trz7Can't change schema of existing table from '%s' to '%s'r^r0rYz2Can't redefine 'quote' or 'quote_schema' argumentsr-cSsg|]}|j<00>qSr)r)rzrurrr<00>
<listcomp>Is z(Table._init_existing.<locals>.<listcomp>)zquotez quote_schema) rIrrrKrurrf<00>remover-rmrVrlr*) r#r(r+r[r\r]rr^rurXrsrrrrO.s8       zTable._init_existingcKs|j|<00>dS)N)<01>_validate_dialect_kwargs)r#r+rrrrlSszTable._extra_kwargscCsdS)Nr)r#rrr<00>_init_collectionsVszTable._init_collectionscCsdS)Nr)r#rrr<00>_reset_exportedYszTable._reset_exportedcCs<>x<>|jD]<5D>}|jr
|jjdk r
t|jjtjj<00>r
|j s_|jdkr
t|j td<00>t
f<00>r
|j dks<>|j j r
|Sq
WdS)NZ ignore_fk) <0A> primary_key<65> autoincrement<6E>typeZ_type_affinity<74>
issubclassr Z INTEGERTYPErh<00>
isinstance<EFBFBD>default<6C>Sequence<63>server_default<6C> reflected)r#<00>colrrr<00>_autoincrement_column\s 
 zTable._autoincrement_columncCst|j|j<00>S)a_Return the 'key' for this :class:`.Table`.
This value is used as the dictionary key within the
:attr:`.MetaData.tables` collection. It is typically the same
as that of :attr:`.Table.name` for a table with no
:attr:`.Table.schema` set; otherwise it is typically of the form
``schemaname.tablename``.
)rrr)r#rrrrXis z Table.keycs[ddjt<00>j<00>gt<00>j<00>gdd<00><00>jD<><17>fdd<00>dgD<><17>S)Nz Table(%s)z, cSsg|]}t|<00><00>qSr)<01>repr)rz<00>xrrrr~ys z"Table.__repr__.<locals>.<listcomp>cs/g|]%}d|tt<00>|<00><00>f<16>qS)z%s=%s)r<><00>getattr)rz<00>k)r#rrr~zs r)<05>joinr<6E>rrV<00>columns)r#r)r#rr/vs 3zTable.__repr__cCst|j|j<00>S)N)r<00> descriptionr)r#rrr<00>__str__|sz Table.__str__cCs|jr|jjpdS)z2Return the connectable associated with this Table.N)rVrt)r#rrrrtsz
Table.bindcCs|jj|<00>dS)a<>Add a 'dependency' for this Table.
This is another Table object which must be created
first before this one can, or dropped after this one.
Usually, dependencies between tables are determined via
ForeignKey objects. However, for other situations that
create dependencies outside of foreign keys (rules, inheriting),
this method can manually establish such a link.
N)ri<00>add)r#r?rrr<00>add_is_dependent_on<6F>s zTable.add_is_dependent_oncCs|j|<00>dS)azAppend a :class:`~.schema.Column` to this :class:`~.schema.Table`.
The "key" of the newly added :class:`~.schema.Column`, i.e. the
value of its ``.key`` attribute, will then be available
in the ``.c`` collection of this :class:`~.schema.Table`, and the
column definition will be included in any CREATE TABLE, SELECT,
UPDATE, etc. statements generated from this :class:`~.schema.Table`
construct.
Note that this does **not** change the definition of the table
as it exists within any underlying database, assuming that
table has already been created in the database. Relational
databases support the addition of columns to existing tables
using the SQL ALTER command, which would need to be
emitted for an already-existing table that doesn't contain
the newly added column.
N)r')r#<00>columnrrr<00> append_column<6D>szTable.append_columncCs|j|<00>dS)a<>Append a :class:`~.schema.Constraint` to this
:class:`~.schema.Table`.
This has the effect of the constraint being included in any
future CREATE TABLE statement, assuming specific DDL creation
events have not been associated with the given
:class:`~.schema.Constraint` object.
Note that this does **not** produce the constraint within the
relational database automatically, for a table that already exists
in the database. To add a constraint to an
existing relational database table, the SQL ALTER command must
be used. SQLAlchemy also provides the
:class:`.AddConstraint` construct which can produce this SQL when
invoked as an executable clause.
N)r')r#ryrrr<00>append_constraint<6E>szTable.append_constraintcs<<00><00>fdd<00>}tj|d<00>jdd<00>|<00>dS)zzAppend a DDL event listener to this ``Table``.
.. deprecated:: 0.7
See :class:`.DDLEvents`.
cs<00><00>||<00>dS)Nr)<03>targetr$rU)<02>
event_name<EFBFBD>listenerrr<00>adapt_listener<65>sz1Table.append_ddl_listener.<locals>.adapt_listener<65><00>-<2D>_N)rrk<00>replace)r#r<>r<>r<>r)r<>r<>r<00>append_ddl_listener<65>szTable.append_ddl_listenercCs&|j|j|j|<00>||_dS)N)rPrrrV)r#rVrrr<00> _set_parent<6E>szTable._set_parentTFcKs7|stj|d||<00>S|r/t|j<00>SgSdS)N<>column_collections)rr,<00>listr<74>)r#r<><00>schema_visitorrUrrrr,<00>s  zTable.get_childrenNcCs=|dkrt|<00>}n|j|jj|jd|j<00>S)z!Return True if this table exists.Nr)r rqrrZ has_tablerr)r#rtrrr<00>exists<74>s z Table.existscCs8|dkrt|<00>}n|jtj|d|<00>dS)z<>Issue a ``CREATE`` statement for this
:class:`.Table`, using the given :class:`.Connectable`
for connectivity.
.. seealso::
:meth:`.MetaData.create_all`.
N<>
checkfirst)r <00> _run_visitorr<00>SchemaGenerator)r#rtr<>rrr<00>create<74>s
 z Table.createcCs8|dkrt|<00>}n|jtj|d|<00>dS)z<>Issue a ``DROP`` statement for this
:class:`.Table`, using the given :class:`.Connectable`
for connectivity.
.. seealso::
:meth:`.MetaData.drop_all`.
Nr<4E>)r r<>r<00> SchemaDropper)r#rtr<>rrr<00>drop<6F>s
 z
Table.dropc sU|dkr|j}n|tkr0|j}n|dkrH|j}nt||<00>}||jkr<>tjd|j<16>|j|Sg}x*|jD]}|j |j
d|<00><01>q<>Wt ||d|||j <00><01>x<>|j D]<5D>}t|t<00>rY|j}|r|||||<00>} n||jkr1|nd} <00>j|j
d| d<00><00><02>q<>|js<>t|t<00>r<>t|j<00>dkr<>t|j<00>djr<>q<>n<00>j|j
d|d<00><00><02>q<>q<>Wx}|jD]r}
t|
j<00>dkr t|
j<00>djr q<>nt|
jd|
j<00>fdd <00>|
jj<00>D<>|
j <00>q<>W|j<00><00>S)
a`
Return a copy of this :class:`.Table` associated with a different
:class:`.MetaData`.
E.g.::
m1 = MetaData()
user = Table('user', m1, Column('id', Integer, priamry_key=True))
m2 = MetaData()
user_copy = user.tometadata(m2)
:param metadata: Target :class:`.MetaData` object, into which the
new :class:`.Table` object will be created.
:param schema: optional string name indicating the target schema.
Defaults to the special symbol :attr:`.RETAIN_SCHEMA` which indicates
that no change to the schema name should be made in the new
:class:`.Table`. If set to a string name, the new :class:`.Table`
will have this new name as the ``.schema``. If set to ``None``, the
schema will be set to that of the schema set on the target
:class:`.MetaData`, which is typically ``None`` as well, unless
set explicitly::
m2 = MetaData(schema='newschema')
# user_copy_one will have "newschema" as the schema name
user_copy_one = user.tometadata(m2, schema=None)
m3 = MetaData() # schema defaults to None
# user_copy_two will have None as the schema name
user_copy_two = user.tometadata(m3, schema=None)
:param referred_schema_fn: optional callable which can be supplied
in order to provide for the schema name that should be assigned
to the referenced table of a :class:`.ForeignKeyConstraint`.
The callable accepts this parent :class:`.Table`, the
target schema that we are changing to, the
:class:`.ForeignKeyConstraint` object, and the existing
"target schema" of that constraint. The function should return the
string schema name that should be applied.
E.g.::
def referred_schema_fn(table, to_schema,
constraint, referred_schema):
if referred_schema == 'base_tables':
return referred_schema
else:
return to_schema
new_table = table.tometadata(m2, schema="alt_schema",
referred_schema_fn=referred_schema_fn)
.. versionadded:: 0.9.2
:param name: optional string name indicating the target table name.
If not specified or None, the table name is retained. This allows
a :class:`.Table` to be copied to the same :class:`.MetaData` target
with a new name.
.. versionadded:: 1.0.0
NzBTable '%s' already exists within the given MetaData - not copying.r<00> target_tablerr<00>uniquecsg|]}<00>j|<19>qSr)ru)rzr<>)r?rrr~vs z$Table.tometadata.<locals>.<listcomp>)r<00> RETAIN_SCHEMArrrLr<00>warnr<6E>r<><00>appendr2r>r+rer<><00>ForeignKeyConstraint<6E>_referred_schemar<61><00> _type_bound<6E>UniqueConstraint<6E>lenr<6E>r<>rd<00>index<65>Index<65>keysr5) r#rVrZreferred_schema_fnrrXr(ruZreferred_schemaZfk_constraint_schemar<61>r)r?r<00>
tometadatasTB              zTable.tometadata)$r6r7r8r9r:rDr;rr<rYrZrQrmrxr}rOrlr<>r<>r=r<>rXr/r<>rtr<>r<>r<>r<>r<>r,r<>r<>r<>r<>r<>rr)rprr>zs@ <0C> :! 7 %          
 r>cs<>eZdZdZdZ<00>fdd<00>Zdd<00>Zdd<00>Zd d
<00>Zd d <00>Z d d<00>Z
dd<00>Z dd<00>Z dd<00>Z ddddd<00>Zddd<00>Z<00>S)<1B>Columnz(Represents a column in a database table.r<>cs<>|jdd<00>}|jdd<00>}t|<00>}|rt|dtj<00>r|dk rjtjd<00><00>n|jd<00>}qn|r<>|d}t|d<00>r<>|dk r<>tjd<00><00>n|jd<00>}q<>n|dk r<>t||jdd<00><00>}nd|krtjd <00><00>nt t
|<00>j ||<00>|jd
|<00>|_ |jd d <00>|_ |jd |j <0C>|_|jdd<00>|_|jdd<00>|_|jdd<00>|_|jdd<00>|_|jdd<00>|_|jdd <00>|_|jdd<00>|_|jdd<00>|_|jdd<00>|_t<00>|_t<00>|_d|krk|jd<00>|_n%t|jt<00>r<>|jj|<00>n|jdk r0t|jtt f<00>r<>|j!|j<00>q0t"|jdd <00>rt|jtj#<00>rtj$d|j |jf<16>qn|j!t|j<00><00>n|jdk r<>t|jt%<00>rm|j!|jj&d <00><00>q<>|j!t'|j<00><00>n|jdk r<>t|jtt f<00>r<>|j!|j<00>q<>|j!t|jdd<00><01>n|jdk r;t|jt%<00>r|j!|jj&d<00><00>q;|j!t'|jdd<00><01>n|j(|<00>tj)|<00>d|krv|jd<00>|_*n|r<>tjdt+t|<00><00><17><00>ndS)a<>,
Construct a new ``Column`` object.
:param name: The name of this column as represented in the database.
This argument may be the first positional argument, or specified
via keyword.
Names which contain no upper case characters
will be treated as case insensitive names, and will not be quoted
unless they are a reserved word. Names with any number of upper
case characters will be quoted and sent exactly. Note that this
behavior applies even for databases which standardize upper
case names as case insensitive such as Oracle.
The name field may be omitted at construction time and applied
later, at any time before the Column is associated with a
:class:`.Table`. This is to support convenient
usage within the :mod:`~sqlalchemy.ext.declarative` extension.
:param type\_: The column's type, indicated using an instance which
subclasses :class:`~sqlalchemy.types.TypeEngine`. If no arguments
are required for the type, the class of the type can be sent
as well, e.g.::
# use a type with arguments
Column('data', String(50))
# use no arguments
Column('level', Integer)
The ``type`` argument may be the second positional argument
or specified by keyword.
If the ``type`` is ``None`` or is omitted, it will first default to
the special type :class:`.NullType`. If and when this
:class:`.Column` is made to refer to another column using
:class:`.ForeignKey` and/or :class:`.ForeignKeyConstraint`, the type
of the remote-referenced column will be copied to this column as
well, at the moment that the foreign key is resolved against that
remote :class:`.Column` object.
.. versionchanged:: 0.9.0
Support for propagation of type to a :class:`.Column` from its
:class:`.ForeignKey` object has been improved and should be
more reliable and timely.
:param \*args: Additional positional arguments include various
:class:`.SchemaItem` derived constructs which will be applied
as options to the column. These include instances of
:class:`.Constraint`, :class:`.ForeignKey`, :class:`.ColumnDefault`,
and :class:`.Sequence`. In some cases an equivalent keyword
argument is available such as ``server_default``, ``default``
and ``unique``.
:param autoincrement: This flag may be set to ``False`` to
indicate an integer primary key column that should not be
considered to be the "autoincrement" column, that is
the integer primary key column which generates values
implicitly upon INSERT and whose value is usually returned
via the DBAPI cursor.lastrowid attribute. It defaults
to ``True`` to satisfy the common use case of a table
with a single integer primary key column. If the table
has a composite primary key consisting of more than one
integer column, set this flag to True only on the
column that should be considered "autoincrement".
The setting *only* has an effect for columns which are:
* Integer derived (i.e. INT, SMALLINT, BIGINT).
* Part of the primary key
* Not refering to another column via :class:`.ForeignKey`, unless
the value is specified as ``'ignore_fk'``::
# turn on autoincrement for this column despite
# the ForeignKey()
Column('id', ForeignKey('other.id'),
primary_key=True, autoincrement='ignore_fk')
It is typically not desirable to have "autoincrement" enabled
on such a column as its value intends to mirror that of a
primary key column elsewhere.
* have no server side or client side defaults (with the exception
of Postgresql SERIAL).
The setting has these two effects on columns that meet the
above criteria:
* DDL issued for the column will include database-specific
keywords intended to signify this column as an
"autoincrement" column, such as AUTO INCREMENT on MySQL,
SERIAL on Postgresql, and IDENTITY on MS-SQL. It does
*not* issue AUTOINCREMENT for SQLite since this is a
special SQLite flag that is not required for autoincrementing
behavior.
.. seealso::
:ref:`sqlite_autoincrement`
* The column will be considered to be available as
cursor.lastrowid or equivalent, for those dialects which
"post fetch" newly inserted identifiers after a row has
been inserted (SQLite, MySQL, MS-SQL). It does not have
any effect in this regard for databases that use sequences
to generate primary key identifiers (i.e. Firebird, Postgresql,
Oracle).
.. versionchanged:: 0.7.4
``autoincrement`` accepts a special value ``'ignore_fk'``
to indicate that autoincrementing status regardless of foreign
key references. This applies to certain composite foreign key
setups, such as the one demonstrated in the ORM documentation
at :ref:`post_update`.
:param default: A scalar, Python callable, or
:class:`.ColumnElement` expression representing the
*default value* for this column, which will be invoked upon insert
if this column is otherwise not specified in the VALUES clause of
the insert. This is a shortcut to using :class:`.ColumnDefault` as
a positional argument; see that class for full detail on the
structure of the argument.
Contrast this argument to :paramref:`.Column.server_default`
which creates a default generator on the database side.
.. seealso::
:ref:`metadata_defaults_toplevel`
:param doc: optional String that can be used by the ORM or similar
to document attributes. This attribute does not render SQL
comments (a future attribute 'comment' will achieve that).
:param key: An optional string identifier which will identify this
``Column`` object on the :class:`.Table`. When a key is provided,
this is the only identifier referencing the ``Column`` within the
application, including ORM attribute mapping; the ``name`` field
is used only when rendering SQL.
:param index: When ``True``, indicates that the column is indexed.
This is a shortcut for using a :class:`.Index` construct on the
table. To specify indexes with explicit names or indexes that
contain multiple columns, use the :class:`.Index` construct
instead.
:param info: Optional data dictionary which will be populated into the
:attr:`.SchemaItem.info` attribute of this object.
:param nullable: If set to the default of ``True``, indicates the
column will be rendered as allowing NULL, else it's rendered as
NOT NULL. This parameter is only used when issuing CREATE TABLE
statements.
:param onupdate: A scalar, Python callable, or
:class:`~sqlalchemy.sql.expression.ClauseElement` representing a
default value to be applied to the column within UPDATE
statements, which wil be invoked upon update if this column is not
present in the SET clause of the update. This is a shortcut to
using :class:`.ColumnDefault` as a positional argument with
``for_update=True``.
:param primary_key: If ``True``, marks this column as a primary key
column. Multiple columns can have this flag set to specify
composite primary keys. As an alternative, the primary key of a
:class:`.Table` can be specified via an explicit
:class:`.PrimaryKeyConstraint` object.
:param server_default: A :class:`.FetchedValue` instance, str, Unicode
or :func:`~sqlalchemy.sql.expression.text` construct representing
the DDL DEFAULT value for the column.
String types will be emitted as-is, surrounded by single quotes::
Column('x', Text, server_default="val")
x TEXT DEFAULT 'val'
A :func:`~sqlalchemy.sql.expression.text` expression will be
rendered as-is, without quotes::
Column('y', DateTime, server_default=text('NOW()'))
y DATETIME DEFAULT NOW()
Strings and text() will be converted into a
:class:`.DefaultClause` object upon initialization.
Use :class:`.FetchedValue` to indicate that an already-existing
column will generate a default value on the database side which
will be available to SQLAlchemy for post-fetch after inserts. This
construct does not specify any DDL and the implementation is left
to the database, such as via a trigger.
.. seealso::
:ref:`server_defaults`
:param server_onupdate: A :class:`.FetchedValue` instance
representing a database-side default generation function. This
indicates to SQLAlchemy that a newly generated value will be
available after updates. This construct does not specify any DDL
and the implementation is left to the database, such as via a
trigger.
:param quote: Force quoting of this column's name on or off,
corresponding to ``True`` or ``False``. When left at its default
of ``None``, the column identifier will be quoted according to
whether the name is case sensitive (identifiers with at least one
upper case character are treated as case sensitive), or if it's a
reserved word. This flag is only needed to force quoting of a
reserved word which is not known by the SQLAlchemy dialect.
:param unique: When ``True``, indicates that this column contains a
unique constraint, or if ``index`` is ``True`` as well, indicates
that the :class:`.Index` should be created with the unique flag.
To specify multiple columns in the constraint/index or to specify
an explicit name, use the :class:`.UniqueConstraint` or
:class:`.Index` constructs explicitly.
:param system: When ``True``, indicates this is a "system" column,
that is a column which is automatically made available by the
database, and should not be included in the columns list for a
``CREATE TABLE`` statement.
For more elaborate scenarios where columns should be
conditionally rendered differently on different backends,
consider custom compilation rules for :class:`.CreateColumn`.
.. versionadded:: 0.8.3 Added the ``system=True`` parameter to
:class:`.Column`.
rN<>type_rz0May not pass name positionally and as a keyword.Z
_sqla_typez1May not pass type_ positionally and as a keyword.r0z9Explicit 'name' is required when sending 'quote' argumentrXr<>F<>nullabler<65>r<><00>server_onupdater<65>r<><00>system<65>doc<6F>onupdater<65>T<>_proxiesZ_warn_on_bytestringz?Unicode column '%s' has non-unicode default value %r specified.<2E>
for_updater-z$Unknown arguments passed to Column: ),rIr<>r<>r<00> string_typesrrK<00>hasattrrrbr<>rZrXr<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>rcrerhr<>r<>r r'<00> ColumnDefaultr<74>r<>r<><00> binary_typer<65><00> FetchedValue<75>_as_for_update<74> DefaultClauser*<00>set_creation_orderr-r<>)r#r(r+rr<>Zcoltype)rprrrZ<00>s<><00>   
           zColumn.__init__cCsX|jdkrdS|jdk rM|jjrC|jjd|jS|jSn|jSdS)Nz (no name)r)rr?Znamed_with_columnr<6E>)r#rrrr<><00>s 
zColumn.__str__cCs8x1|jD]"}|jjj|j<00>r
dSq
WdSdS)zOReturn True if this Column references the given column via foreign
key.TFN)rhr<>Z proxy_set<65> intersection)r#r<><00>fkrrr<00>
references<EFBFBD>szColumn.referencescCs|j|<00>dS)N)r')r#r<>rrr<00>append_foreign_key<65>szColumn.append_foreign_keycs7g}<00>j<00>jkr(|jd<00>n<00>jrA|jd<00>n<00>jsZ|jd<00>n<00>jrs|jd<00>n<00>jr<>|jd<00>n<00>jr<>|jd<00>nddjt <00>j<00>gt <00>j
<00>gd d
<00><00>j D<>d d
<00><00>j D<><17>j dk rd <00>j jpd g<17>fdd
<00>|D<><17>S)NrXr<>r<>r<>r<>r<>z
Column(%s)z, cSs(g|]}|dk rt|<00><00>qS)N)r<>)rzr<>rrrr~<00>s z#Column.__repr__.<locals>.<listcomp>cSsg|]}t|<00><00>qSr)r<>)rzr<>rrrr~<00>s z
table=<%s>z
table=Nonecs/g|]%}d|tt<00>|<00><00>f<16>qS)z%s=%s)r<>r<>)rzr<>)r#rrr~<00>s )rXrr<>r<>r<>r<>r<>r<>r<>r<>r<>rhrer?r<>)r#Zkwargr)r#rr/<00>s       mzColumn.__repr__cs8|jstjd<00><00>n|jdkr9|j|_nt|dd<00>}|dk r<>|<00>k r<>tjd|j|jf<16><00>n|j<00>jkr
<01>jj|j<00>}||k r
xL|jD]>}<00>jj |<00>|j
<00>j kr<><00>j j |j
<00>q<>q<>Wq
n<00>jj |<00>|j rF<01>j j|<00>tjj<00><00>n4|j<00>j krztjd|j<00>jf<16><00>n<00>|_|jr<>t|jtj<00>r<>tjd<00><00>ntd|dt|j<00><00>nI|jrt|jtj<00>rtjd<00><00>n<00>jt|j<00><00>n|j<00>fdd <00><00>dS)
NzfColumn must be constructed with a non-blank name or assign a non-blank .name before adding to a Table.r?z1Column object '%s' already assigned to Table '%s'zTTrying to redefine primary-key column '%s' as a non-primary-key column on table '%s'z<>The 'index' keyword argument on Column is boolean only. To create indexes with a specific name, create an explicit Index object external to the Table.r<>z<>The 'unique' keyword argument on Column is boolean only. To create unique constraints or indexes with a specific name, append an explicit UniqueConstraint to the Table's list of elements, or create an explicit Index object external to the Table.cs |j<00><00>S)N)<01>_set_remote_table)r<>)r?rrrv6sz$Column._set_parent.<locals>.<lambda>)rrrKrXr<>r<>rfrGrhrryrer<>r<><00>_replacer>r<>Z_resetrjr?r<>r<>rr<>r<>rMr<>r<>r<><00>_setup_on_memoized_fks)r#r?<00>existingr<67>r<>r)r?rr<><00>sL          zColumn._set_parentcCs<>|jj|jfdf|jj|jfdfg}xf|D]^\}}||jjjkr=x:|jjj|D]"}|j|krr||<00>qrqrWq=q=WdS)NFT)r?rXrrV<00> _fk_memos<6F> link_to_name)r#roZfk_keys<79>fk_keyr<79>r<>rrrr<>8szColumn._setup_on_memoized_fkscCs9|jdk r"|||j<00>ntj|d|<00>dS)NrR)r?rrk)r#rorrr<00>_on_table_attachCszColumn._on_table_attachc s<><00>fdd<00>|jD<><00>fdd<00>|jD<>}|j}t|t<00>r`|j<00><00>}n|jd|jd|d|jd|j d|j
d |j d
|j d |j d |jd |jd|jd|jd|jd|j|<00>}|j|<00>S)zgCreate a copy of this ``Column``, unitialized.
This is used in ``Table.tometadata``.
cs(g|]}|js|j<00><00><00>qSr)r<>r2)rzru)rUrrr~Rs zColumn.copy.<locals>.<listcomp>cs(g|]}|js|j<00><00><00>qSr)ryr2)rzru)rUrrr~Ss rr<>rXr<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>)rerhr<>r<>r r2<00> _constructorrrXr<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r5)r#rUr(r<>rur)rUrr2Is,                z Column.copyNFcKsbdd<00>|jD<>}|dkrC|jdkrCtjd<00><00>ny||j|rgt|pa|j<00>n |ps|j|jd|r<>|n|r<>|n|jd|jd|j d|g|<00>}Wn,t
k
r<>t j t
d |j <16><00>YnX||_|jj|<00>|jdk r/|jj|j|_n|jrK|jj|<00>n|jj||<00>|S)
a$Create a *proxy* for this column.
This is a copy of this ``Column`` referenced by a different parent
(such as an alias or select statement). The column should
be used only in select scenarios, as its full DDL/default
information is not transferred.
cSs(g|]}t|jd|j<00><01>qS)<01> _constraint)<03>
ForeignKeyr<EFBFBD>ry)rz<00>frrrr~ws z&Column._make_proxy.<locals>.<listcomp>Nz^Cannot initialize a sub-selectable with this Column object until its 'name' has been assigned.rXr<>r<>r<>z<>Could not create a copy of this %r object. Ensure the class includes a _constructor() attribute or method which accepts the standard Column constructor arguments, or references the Column class itself.)rhrrrNr<>rr<>rXr<>r<>rFrZraise_from_causerpr?rfr<>Z _is_clone_ofr<66>r3rR)r#<00>
selectablerrXZname_is_truncatablerUr<>rurrr<00> _make_proxyms4
  ' !     zColumn._make_proxycKsQ|r=dd<00>|j|jfD<>t|j<00>t|j<00>Stj||<00>SdS)NcSs"g|]}|dk r|<00>qS)Nr)rzr<>rrrr~<00>s z'Column.get_children.<locals>.<listcomp>)r<>r<>r<>rhrerr,)r#r<>r+rrrr,<00>s7zColumn.get_children)r6r7r8r9r:rZr<>r<>r<>r/r<>r<>r<>r2r<>r,rr)rprr<>{s <12>Q
  :  $,r<>c @s3eZdZdZdZdddddddddddd<00>
Zdd<00>Zdd d
<00>Zddd d <00>Ze d d<00><00>Z
dd<00>Z e e<00>Z dd<00>Z dd<00>Zejdd<00><00>Zdd<00>Zdd<00>Zdd<00>Zejdd<00><00>Zdd <00>Zd!d"<00>Zd#d$<00>Zd%d&<00>ZdS)'r<>a<>Defines a dependency between two columns.
``ForeignKey`` is specified as an argument to a :class:`.Column` object,
e.g.::
t = Table("remote_table", metadata,
Column("remote_id", ForeignKey("main_table.id"))
)
Note that ``ForeignKey`` is only a marker object that defines
a dependency between two columns. The actual constraint
is in all cases represented by the :class:`.ForeignKeyConstraint`
object. This object will be generated automatically when
a ``ForeignKey`` is associated with a :class:`.Column` which
in turn is associated with a :class:`.Table`. Conversely,
when :class:`.ForeignKeyConstraint` is applied to a :class:`.Table`,
``ForeignKey`` markers are automatically generated to be
present on each associated :class:`.Column`, which are also
associated with the constraint object.
Note that you cannot define a "composite" foreign key constraint,
that is a constraint between a grouping of multiple parent/child
columns, using ``ForeignKey`` objects. To define this grouping,
the :class:`.ForeignKeyConstraint` object must be used, and applied
to the :class:`.Table`. The associated ``ForeignKey`` objects
are created automatically.
The ``ForeignKey`` objects associated with an individual
:class:`.Column` object are available in the `foreign_keys` collection
of that column.
Further examples of foreign key configuration are in
:ref:`metadata_foreignkeys`.
Z foreign_keyNFc Ks;||_t|jtj<00>r*d|_n<>t|jd<00>rQ|jj<00>|_n |j|_t|jt<00>s<>tj d|j<16><00>n:t|jj
tj t f<00>s<>tj d|jj
<16><00>n||_ d|_||_||_||_||_||_||_| |_|
|_| r.| |_n| |_dS)a
Construct a column-level FOREIGN KEY.
The :class:`.ForeignKey` object when constructed generates a
:class:`.ForeignKeyConstraint` which is associated with the parent
:class:`.Table` object's collection of constraints.
:param column: A single target column for the key relationship. A
:class:`.Column` object or a column name as a string:
``tablename.columnkey`` or ``schema.tablename.columnkey``.
``columnkey`` is the ``key`` which has been assigned to the column
(defaults to the column name itself), unless ``link_to_name`` is
``True`` in which case the rendered name of the column is used.
.. versionadded:: 0.7.4
Note that if the schema name is not included, and the
underlying :class:`.MetaData` has a "schema", that value will
be used.
:param name: Optional string. An in-database name for the key if
`constraint` is not provided.
:param onupdate: Optional string. If set, emit ON UPDATE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.
:param ondelete: Optional string. If set, emit ON DELETE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.
:param deferrable: Optional bool. If set, emit DEFERRABLE or NOT
DEFERRABLE when issuing DDL for this constraint.
:param initially: Optional string. If set, emit INITIALLY <value> when
issuing DDL for this constraint.
:param link_to_name: if True, the string name given in ``column`` is
the rendered name of the referenced column, not its locally
assigned ``key``.
:param use_alter: passed to the underlying
:class:`.ForeignKeyConstraint` to indicate the constraint should
be generated/dropped externally from the CREATE TABLE/ DROP TABLE
statement. See :paramref:`.ForeignKeyConstraint.use_alter`
for further description.
.. seealso::
:paramref:`.ForeignKeyConstraint.use_alter`
:ref:`use_alter`
:param match: Optional string. If set, emit MATCH <value> when issuing
DDL for this constraint. Typical values include SIMPLE, PARTIAL
and FULL.
:param info: Optional data dictionary which will be populated into the
:attr:`.SchemaItem.info` attribute of this object.
.. versionadded:: 1.0.0
:param \**dialect_kw: Additional keyword arguments are dialect
specific, and passed in the form ``<dialectname>_<argname>``. The
arguments are ultimately handled by a corresponding
:class:`.ForeignKeyConstraint`. See the documentation regarding
an individual dialect at :ref:`dialect_toplevel` for detail on
documented arguments.
.. versionadded:: 0.9.2
N<>__clause_element__z9String, Column, or Column-bound argument expected, got %rz8ForeignKey received Column not bound to a Table, got: %r)<19>_colspecr<63>rr<><00> _table_columnr<6E>r<>rrrKr?ZNoneTyperry<00>parent<6E> use_alterrr<><00>ondelete<74>
deferrable<EFBFBD> initiallyr<79><00>matchr-<00>_unvalidated_dialect_kw) r#r<>r<>r<>rr<>r<>r<>r<>r<>r<>r-<00>
dialect_kwrrrrZ<00>s8M              zForeignKey.__init__cCsd|j<00>S)NzForeignKey(%r))<01> _get_colspec)r#rrrr/>szForeignKey.__repr__cCsst|jd|<00>d|jd|jd|jd|jd|jd|jd|jd |j |j
<00>}|j |<00>S)
a<EFBFBD>Produce a copy of this :class:`.ForeignKey` object.
The new :class:`.ForeignKey` will not be bound
to any :class:`.Column`.
This method is usually used by the internal
copy procedures of :class:`.Column`, :class:`.Table`,
and :class:`.MetaData`.
:param schema: The returned :class:`.ForeignKey` will
reference the original table and column name, qualified
by the given string schema name.
rr<>rr<>r<>r<>r<>r<>r<>) r<>r<>r<>rr<>r<>r<>r<>r<>r<>r<>r5)r#rr<>rrrr2As        zForeignKey.copycCs<>|r>|j\}}}|dk r-|}nd|||fS|r~|j\}}}|rmd|||fSd||fSn3|jdk r<>d|jjj|jjfS|jSdS)z<>Return a string based 'column specification' for this
:class:`.ForeignKey`.
This is usually the equivalent of the string-based "tablename.colname"
argument first passed to the object's constructor.
Nz%s.%s.%sz%s.%s)<06>_column_tokensr<73>r?rjrXr<>)r#r<00>
table_nameZ_schema<6D>tname<6D>colnamerrrr<>_s  zForeignKey._get_colspeccCs |jdS)Nr)r<>)r#rrrr<>xszForeignKey._referred_schemacCsX|jdk r5|jjdkr%dS|jjjSn|j\}}}t||<00>SdS)N)r<>r?rXr<>r)r#rr<>r<>rrr<00>
_table_key|s zForeignKey._table_keycCs|j|j<00>dk S)z\Return True if the given :class:`.Table` is referenced by this
:class:`.ForeignKey`.N)<02>corresponding_columnr<6E>)r#r?rrrr<><00>szForeignKey.referencescCs|j|j<00>S)z<>Return the :class:`.Column` in the given :class:`.Table`
referenced by this :class:`.ForeignKey`.
Returns None if this :class:`.ForeignKey` does not reference the given
:class:`.Table`.
)r<>r<>)r#r?rrr<00> get_referent<6E>s zForeignKey.get_referentcCs<>|j<00>jd<00>}|dkr:tjd|j<16><00>nt|<00>dkra|j<00>}d}n|j<00>}|j<00>}t|<00>dkr<>dj|<00>}nd}|||fS)z7parse a string-based _colspec into its component parts.rNz,Invalid foreign key column specification: %srr)r<><00>splitrrKr<>r<>rIr<>)r#<00>mr<6D>r<>rrrrr<><00>s     zForeignKey._column_tokenscCs<>|jdkr!tjd<00><00>n$|jjdkrEtjd<00><00>n|jj}xH|jjD].}t|t<00>r^|j|ks<>t<00>Pq^q^Wds<>t<00>|j\}}}|dkr<>|j j
dk r<>|j j
}nt ||<00>}|||fS)NzLthis ForeignKey object does not yet have a parent Column associated with it.zCthis ForeignKey's parent column is not yet associated with a Table.F) r<>rrNr?Z base_columnsr<73>r<><00>AssertionErrorr<72>rVrr)r#<00> parenttablerurr<>r<><00>tablekeyrrr<00>_resolve_col_tokens<6E>s"    zForeignKey._resolve_col_tokenscCst|jd<00>s!||j_n|jj|ks9t<00>d}|dkrr|j}|jj|jjd<00>}nY|jr<>|}xG|jD]}|j |kr<>|}q<>q<>Wn|}|jj|d<00>}|dkr t
j d|j |j |j |f|j |<00><00>n|j |<00>dS)N<>_referred_tableziCould not initialize target column for ForeignKey '%s' on table '%s': table '%s' has no column named '%s')r<>ryr<>r<>r<>rurGrXr<>rr<00>NoReferencedColumnErrorr<72><00>_set_target_column)r#r<>r?r<><00>_columnrXrurrr<00>_link_to_col_by_colstring<6E>s(    z$ForeignKey._link_to_col_by_colstringcsh|jjjr!<00>j|j_nt|jjt<00>r[<00>fdd<00>}|jj|<00>n<00>|_dS)Ncs%|jjjr!<00>j|j_ndS)N)r<>r<><00>_isnull)r<>)r<>rr<00>set_typesz/ForeignKey._set_target_column.<locals>.set_type)r<>r<>r<>r<>r?r>r<>r<>)r#r<>r<>r)r<>rr<><00>s zForeignKey._set_target_columncCs<>t|jtj<00>r<>|j<00>\}}}||jkr^tjd|j||f|<00><00>q<>|j |jkr<>tj
d|<16><00>q<>tj d|j|j ||f||<00><00>n2t |jd<00>r<>|jj<00>}|S|j}|SdS)a<>Return the target :class:`.Column` referenced by this
:class:`.ForeignKey`.
If no target column has been established, an exception
is raised.
.. versionchanged:: 0.9.0
Foreign key target column resolution now occurs as soon as both
the ForeignKey object and the remote Column to which it refers
are both associated with the same MetaData object.
z|Foreign key associated with column '%s' could not find table '%s' with which to generate a foreign key to target column '%s'z9Table %s is no longer associated with its parent MetaDataziCould not initialize target column for ForeignKey '%s' on table '%s': table '%s' has no column named '%s'r<>N)r<>r<>rr<>r<>rVrZNoReferencedTableErrorr<72>rXrNr<>rr<>r<>)r#r<>r<>r<>r<>rrrr<>
s(   zForeignKey.columncCsc|jdk r0|j|k r0tjd<00><00>n||_|jjj|<00>|jj|j<00>dS)Nz&This ForeignKey already has a parent !)r<>rrNrhr<>r<><00>
_set_table)r#r<>rrrr<>6s   zForeignKey._set_parentcCs<|j<00>\}}}|j|||<00>|jj|<00>dS)N)r<>r<>ry<00>_validate_dest_table)r#r?r<>r<>r<>rrrr<>>szForeignKey._set_remote_tablecCsO|j<00>\}}}||f}||j|krK|j|j|<00>ndS)N)r<>r<>r)r#rVr<><00> table_keyr<79>r<>rrr<00>_remove_from_metadataCs z ForeignKey._remove_from_metadatacCs<>|jdkr<>t|t<00>r<>tggd|jd|jd|jd|jd|jd|j d|j
|j <00>|_|jj ||<00>|jj |<00>n|jj|<00>t|jtj<00>rO|j<00>\}}}||f}||jjkr5|jj|}y|j|||<00>Wq5tjk
r1Yq5Xn|jj|j|<00>nGt|jd<00>r<>|jj<00>}|j|<00>n|j}|j|<00>dS) Nr<4E>rr<>r<>r<>r<>r<>r<>)ryr<>r>r<>r<>rr<>r<>r<>r<>r<>r<><00>_append_elementr'rhr<>r<>rr<>r<>rVrLr<>rr<>r<>r<>r<>r<>r<>)r#r<>r?r<>rr<>r<>r<>rrrrKs4  zForeignKey._set_table)r6r7r8r9r:rZr/r2r<>r;r<>r<>Ztarget_fullnamer<65>r<>rr=r<>r<>r<>r<>r<>r<>r<>rrrrrrr<><00>s. #   q 
   ! ! ,   r<>c@s>eZdZdd<00>Zdd<00>ZZedd<00><00>ZdS)<07>_NotAColumnExprcCstjd|jj<16><00>dS)Nz7This %s cannot be used directly as a column expression.)rrNrpr6)r#rrr<00>_not_a_column_exprqsz"_NotAColumnExpr._not_a_column_exprcCs
|j<00>S)N)r)r#rrrrvvsz_NotAColumnExpr.<lambda>cCs
|j<00>S)N)r)r#rrrrvwsN)r6r7r8rr<>Z
self_groupr;Z _from_objectsrrrrrps  rc@sjeZdZdZdZdZdZdZddd<00>Zdd<00>Z dd d
<00>Z
e d d <00><00>Z dS) <0A>DefaultGeneratorz'Base class for column *default* values.Zdefault_generatorFNcCs ||_dS)N)r<>)r#r<>rrrrZ<00>szDefaultGenerator.__init__cCs1||_|jr!||j_n ||j_dS)N)r<>r<>r<>r<>)r#r<>rrrr<><00>s  zDefaultGenerator._set_parentcKs+|dkrt|<00>}n|j||<00>S)N)r r")r#rtr+rrr<00>execute<74>s zDefaultGenerator.executecCs-t|dd<00>dk r%|jjjSdSdS)z4Return the connectable associated with this default.r<>N)r<>r<>r?rt)r#rrrrt<00>s zDefaultGenerator.bind) r6r7r8r9r:<00> is_sequence<63>is_server_defaultr<74>rZr<>rr;rtrrrrrzs  rcs<>eZdZdZ<00>fdd<00>Zejdd<00><00>Zejdd<00><00>Zejdd <00><00>Z d
d <00>Z
d d <00>Z e e <00>Z dd<00>Z<00>S)r<>a<>A plain default value on a column.
This could correspond to a constant, a callable function,
or a SQL clause.
:class:`.ColumnDefault` is generated automatically
whenever the ``default``, ``onupdate`` arguments of
:class:`.Column` are used. A :class:`.ColumnDefault`
can be passed positionally as well.
For example, the following::
Column('foo', Integer, default=50)
Is equivalent to::
Column('foo', Integer, ColumnDefault(50))
c sett|<00>j|<00>t|t<00>r7tjd<00><00>ntj|<00>rX|j |<00>}n||_
dS)aj"Construct a new :class:`.ColumnDefault`.
:param arg: argument representing the default value.
May be one of the following:
* a plain non-callable Python value, such as a
string, integer, boolean, or other simple type.
The default value will be used as is each time.
* a SQL expression, that is one which derives from
:class:`.ColumnElement`. The SQL expression will
be rendered into the INSERT or UPDATE statement,
or in the case of a primary key column when
RETURNING is not used may be
pre-executed before an INSERT within a SELECT.
* A Python callable. The function will be invoked for each
new row subject to an INSERT or UPDATE.
The callable must accept exactly
zero or one positional arguments. The one-argument form
will receive an instance of the :class:`.ExecutionContext`,
which provides contextual information as to the current
:class:`.Connection` in use as well as the current
statement and parameters.
z4ColumnDefault may not be a server-side default type.N) rbr<>rZr<>r<>rrKr<00>callable<6C>_maybe_wrap_callable<6C>arg)r#r r+)rprrrZ<00>s zColumnDefault.__init__cCstj|j<00>S)N)rr r )r#rrr<00> is_callable<6C>szColumnDefault.is_callablecCst|jt<00>S)N)r<>r r)r#rrr<00>is_clause_element<6E>szColumnDefault.is_clause_elementcCs|j o|j o|j S)N)rrr )r#rrr<00> is_scalar<61>s

zColumnDefault.is_scalarc s<>ytj<00>dd<00>}Wn"tk
r=<01>fdd<00>SYnX|ddk r^t|d<19>pad}t|d<19>|}|dkr<><00>fdd<00>S|d kr<><00>Stjd
<00><00>dS) z<>Wrap callables that don't accept a context.
This is to allow easy compatibility with default callables
that aren't specific to accepting of a context.
Zno_selfTcs<00><00>S)Nr)<01>ctx)rorrrv<00>sz4ColumnDefault._maybe_wrap_callable.<locals>.<lambda><3E>Nrcs<00><00>S)Nr)r)rorrrv<00>srzDColumnDefault Python function takes zero or one positional arguments)rZget_callable_argspecrFr<>rrK)r#roZargspecZ defaultedZ positionalsr)rorr <00>s &  z"ColumnDefault._maybe_wrap_callablecCs|jr dSdSdS)NZcolumn_onupdateZcolumn_default)r<>)r#rrr<00> _visit_name<6D>s zColumnDefault._visit_namecCs d|jS)NzColumnDefault(%r))r )r#rrrr/szColumnDefault.__repr__)r6r7r8r9rZrr=rrrr rr;r:r/rr)rprr<><00>s "   r<>cs eZdZdZdZdZddddddddddddd<00>fdd<00> Zejdd <00><00>Z ejd
d <00><00>Z
ej d <00>d d<00><00>Z <00>fdd<00>Z dd<00>Zdd<00>Zedd<00><00>Zdddd<00>Zdddd<00>Zdd<00>Z<00>S)r<>a<>Represents a named database sequence.
The :class:`.Sequence` object represents the name and configurational
parameters of a database sequence. It also represents
a construct that can be "executed" by a SQLAlchemy :class:`.Engine`
or :class:`.Connection`, rendering the appropriate "next value" function
for the target database and returning a result.
The :class:`.Sequence` is typically associated with a primary key column::
some_table = Table(
'some_table', metadata,
Column('id', Integer, Sequence('some_table_seq'),
primary_key=True)
)
When CREATE TABLE is emitted for the above :class:`.Table`, if the
target platform supports sequences, a CREATE SEQUENCE statement will
be emitted as well. For platforms that don't support sequences,
the :class:`.Sequence` construct is ignored.
.. seealso::
:class:`.CreateSequence`
:class:`.DropSequence`
<20>sequenceTNFcs
tt|<00>jd|<00>t|| <00>|_||_||_||_||_||_ ||_
||_ |
|_ | t kr<>d|_} nF| dk r<>| dkr<>| jr<>| j|_} nt| | <00>|_| |_t|| <00>|_| r|j| <00>ndS)a<>Construct a :class:`.Sequence` object.
:param name: The name of the sequence.
:param start: the starting index of the sequence. This value is
used when the CREATE SEQUENCE command is emitted to the database
as the value of the "START WITH" clause. If ``None``, the
clause is omitted, which on most platforms indicates a starting
value of 1.
:param increment: the increment value of the sequence. This
value is used when the CREATE SEQUENCE command is emitted to
the database as the value of the "INCREMENT BY" clause. If ``None``,
the clause is omitted, which on most platforms indicates an
increment of 1.
:param minvalue: the minimum value of the sequence. This
value is used when the CREATE SEQUENCE command is emitted to
the database as the value of the "MINVALUE" clause. If ``None``,
the clause is omitted, which on most platforms indicates a
minvalue of 1 and -2^63-1 for ascending and descending sequences,
respectively.
.. versionadded:: 1.0.7
:param maxvalue: the maximum value of the sequence. This
value is used when the CREATE SEQUENCE command is emitted to
the database as the value of the "MAXVALUE" clause. If ``None``,
the clause is omitted, which on most platforms indicates a
maxvalue of 2^63-1 and -1 for ascending and descending sequences,
respectively.
.. versionadded:: 1.0.7
:param nominvalue: no minimum value of the sequence. This
value is used when the CREATE SEQUENCE command is emitted to
the database as the value of the "NO MINVALUE" clause. If ``None``,
the clause is omitted, which on most platforms indicates a
minvalue of 1 and -2^63-1 for ascending and descending sequences,
respectively.
.. versionadded:: 1.0.7
:param nomaxvalue: no maximum value of the sequence. This
value is used when the CREATE SEQUENCE command is emitted to
the database as the value of the "NO MAXVALUE" clause. If ``None``,
the clause is omitted, which on most platforms indicates a
maxvalue of 2^63-1 and -1 for ascending and descending sequences,
respectively.
.. versionadded:: 1.0.7
:param cycle: allows the sequence to wrap around when the maxvalue
or minvalue has been reached by an ascending or descending sequence
respectively. This value is used when the CREATE SEQUENCE command
is emitted to the database as the "CYCLE" clause. If the limit is
reached, the next number generated will be the minvalue or maxvalue,
respectively. If cycle=False (the default) any calls to nextval
after the sequence has reached its maximum value will return an
error.
.. versionadded:: 1.0.7
:param schema: Optional schema name for the sequence, if located
in a schema other than the default. The rules for selecting the
schema name when a :class:`.MetaData` is also present are the same
as that of :paramref:`.Table.schema`.
:param optional: boolean value, when ``True``, indicates that this
:class:`.Sequence` object only needs to be explicitly generated
on backends that don't provide another way to generate primary
key identifiers. Currently, it essentially means, "don't create
this sequence on the Postgresql backend, where the SERIAL keyword
creates a sequence for us automatically".
:param quote: boolean value, when ``True`` or ``False``, explicitly
forces quoting of the schema name on or off. When left at its
default of ``None``, normal quoting rules based on casing and
reserved words take place.
:param quote_schema: set the quoting preferences for the ``schema``
name.
:param metadata: optional :class:`.MetaData` object which will be
associated with this :class:`.Sequence`. A :class:`.Sequence`
that is associated with a :class:`.MetaData` gains access to the
``bind`` of that :class:`.MetaData`, meaning the
:meth:`.Sequence.create` and :meth:`.Sequence.drop` methods will
make usage of that engine automatically.
.. versionchanged:: 0.7
Additionally, the appropriate CREATE SEQUENCE/
DROP SEQUENCE DDL commands will be emitted corresponding to this
:class:`.Sequence` when :meth:`.MetaData.create_all` and
:meth:`.MetaData.drop_all` are invoked.
Note that when a :class:`.Sequence` is applied to a :class:`.Column`,
the :class:`.Sequence` is automatically associated with the
:class:`.MetaData` object of that column's parent :class:`.Table`,
when that association is made. The :class:`.Sequence` will then
be subject to automatic CREATE SEQUENCE/DROP SEQUENCE corresponding
to when the :class:`.Table` object itself is created or dropped,
rather than that of the :class:`.MetaData` object overall.
:param for_update: Indicates this :class:`.Sequence`, when associated
with a :class:`.Column`, should be invoked for UPDATE statements
on that column's table, rather than for INSERT statements, when
no value is otherwise present for that column in the statement.
r<>N)rbr<>rZrr<00>start<72> increment<6E>minvalue<75>maxvalue<75>
nominvalue<EFBFBD>
nomaxvalue<EFBFBD>cycle<6C>optionalrHrrVr<00>_key<65> _set_metadata)r#rrrrrrrrrrr0rVrYr<>)rprrrZ&s&l         ! zSequence.__init__cCsdS)NFr)r#rrrr<00>szSequence.is_callablecCsdS)NFr)r#rrrr<00>szSequence.is_clause_elementzsqlalchemy.sql.functions.funccCs|j|d|j<00>S)z<>Return a :class:`.next_value` function element
which will render the appropriate increment function
for this :class:`.Sequence` within any SQL expression.
rt)<02>
next_valuert)r#<00>funcrrrr<00>szSequence.next_valuecs*tt|<00>j|<00>|j|j<00>dS)N)rbr<>r<>r<>r)r#r<>)rprrr<><00>szSequence._set_parentcCs|j|j<00>dS)N)rrV)r#r<>r?rrrr<00>szSequence._set_tablecCs ||_||jj|j<dS)N)rV<00>
_sequencesr)r#rVrrrr<00>s zSequence._set_metadatacCs|jr|jjSdSdS)N)rVrt)r#rrrrt<00>s 
z Sequence.bindcCs8|dkrt|<00>}n|jtj|d|<00>dS)z&Creates this sequence in the database.Nr<4E>)r r<>rr<>)r#rtr<>rrrr<><00>s
  zSequence.createcCs8|dkrt|<00>}n|jtj|d|<00>dS)z&Drops this sequence from the database.Nr<4E>)r r<>rr<>)r#rtr<>rrrr<><00>s
  z Sequence.dropcCstjd|jj<16><00>dS)Nz<4E>This %s cannot be used directly as a column expression. Use func.next_value(sequence) to produce a 'next value' function that's usable as a column element.)rrNrpr6)r#rrrr<00>szSequence._not_a_column_expr)r6r7r8r9r:r rZrr=rr<00> dependenciesrr<>rrr;rtr<>r<>rrr)rprr<>s$    }     r<>c@sgeZdZdZdZdZdZddd<00>Zdd<00>Zdd <00>Z d
d <00>Z
d d <00>Z dS)r<>a<>A marker for a transparent database-side default.
Use :class:`.FetchedValue` when the database is configured
to provide some automatic default for a column.
E.g.::
Column('foo', Integer, FetchedValue())
Would indicate that some trigger or default generator
will create a new value for the ``foo`` column during an
INSERT.
.. seealso::
:ref:`triggered_columns`
TFcCs ||_dS)N)r<>)r#r<>rrrrZ<00>szFetchedValue.__init__cCs$||jkr|S|j|<00>SdS)N)r<><00>_clone)r#r<>rrrr<> szFetchedValue._as_for_updatecCsH|jj|j<00>}|jj|j<00>|jjdd<00>||_|S)Nr<4E>)rprDr1<00>updaterIr<>)r#r<><00>nrrrr# s
 zFetchedValue._clonecCs1||_|jr!||j_n ||j_dS)N)r<>r<>r<>r<>)r#r<>rrrr<> s  zFetchedValue._set_parentcCs tj|<00>S)N)rr.)r#rrrr/ szFetchedValue.__repr__N) r6r7r8r9r
r<><00> has_argumentrZr<>r#r<>r/rrrrr<><00>s    r<>cs@eZdZdZdZdd<00>fdd<00>Zdd<00>Z<00>S)r<>a7A DDL-specified DEFAULT column value.
:class:`.DefaultClause` is a :class:`.FetchedValue`
that also generates a "DEFAULT" clause when
"CREATE TABLE" is emitted.
:class:`.DefaultClause` is generated automatically
whenever the ``server_default``, ``server_onupdate`` arguments of
:class:`.Column` are used. A :class:`.DefaultClause`
can be passed positionally as well.
For example, the following::
Column('foo', Integer, server_default="50")
Is equivalent to::
Column('foo', Integer, DefaultClause("50"))
TFcsOtj|tjdttfd<00>tt|<00>j|<00>||_||_ dS)Nrr )
rZassert_arg_typer<65>rrrbr<>rZr r<>)r#r r<>Z
_reflected)rprrrZ0 s   zDefaultClause.__init__cCsd|j|jfS)Nz DefaultClause(%r, for_update=%r))r r<>)r#rrrr/8 szDefaultClause.__repr__)r6r7r8r9r&rZr/rr)rprr<> s r<>c@s7eZdZdZejddd<00>dd<00><00>ZdS)<08>PassiveDefaultz<74>A DDL-specified DEFAULT column value.
.. deprecated:: 0.6
:class:`.PassiveDefault` is deprecated.
Use :class:`.DefaultClause`.
z0.6zE:class:`.PassiveDefault` is deprecated. Use :class:`.DefaultClause`.FcOstj|||<00>dS)N)r<>rZ)r#r rUrrrrZD szPassiveDefault.__init__N)r6r7r8r9rr<rZrrrrr'= s  r'c@sdeZdZdZdZdddddddd<00>Zedd<00><00>Zd d
<00>Zd d <00>Z dS) <0A>
ConstraintzA table-level SQL constraint.ryNFcKs]||_||_||_|r-||_n||_||_tj|<00>|j|<00>dS)a<>Create a SQL constraint.
:param name:
Optional, the in-database name of this ``Constraint``.
:param deferrable:
Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.
:param initially:
Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.
:param info: Optional data dictionary which will be populated into the
:attr:`.SchemaItem.info` attribute of this object.
.. versionadded:: 1.0.0
:param _create_rule:
a callable which is passed the DDLCompiler object during
compilation. Returns True or False to signal inline generation of
this Constraint.
The AddConstraint and DropConstraint DDL constructs provide
DDLElement's more comprehensive "conditional DDL" approach that is
passed a database connection when DDL is being issued. _create_rule
is instead called during any CREATE TABLE compilation, where there
may not be any transaction/connection in progress. However, it
allows conditional compilation of the constraint even for backends
which do not support addition of constraints through ALTER TABLE,
which currently includes SQLite.
_create_rule is used by some types to create constraints.
Currently, its call signature is subject to change at any time.
:param \**dialect_kw: Additional keyword arguments are dialect
specific, and passed in the form ``<dialectname>_<argname>``. See
the documentation regarding an individual dialect at
:ref:`dialect_toplevel` for detail on documented arguments.
N) rr<>r<>r-<00> _create_ruler<65>rr<>r<>)r#rr<>r<>r)r-r<>r<>rrrrZQ s-       zConstraint.__init__c CsEyt|jt<00>r|jSWntk
r1YnXtjd<00><00>dS)NzdThis constraint is not bound to a table. Did you mean to call table.append_constraint(constraint) ?)r<>r<>r><00>AttributeErrorrrN)r#rrrr?<00> s  zConstraint.tablecCs||_|jj|<00>dS)N)r<>rer<>)r#r<>rrrr<><00> s zConstraint._set_parentcKs t<00><00>dS)N)<01>NotImplementedError)r#rUrrrr2<00> szConstraint.copy)
r6r7r8r9r:rZr;r?r<>r2rrrrr(L s  6 r(cCsCt|d<00>r|j<00>}nt|t<00>s?tjd<00><00>n|S)Nr<4E>zschema.Column object expected)r<>r<>r<>r<>rrK)<01>elementrrr<00>_to_schema_column<6D> s
r-cCsWt|d<00>r|j<00>}nt|tjtf<17>sSd}tj||<16><00>n|S)Nr<4E>z1Element %r is not a string name or column element)r<>r<>r<>rr<>rrrK)r,rWrrr<00>_to_schema_column_or_string<6E> s r.c@sUeZdZdZdZdd<00>Zedd<00><00>Zddd<00>Zd d
<00>Z dS) <0B>ColumnCollectionMixinNFcOsT|jdd<00>}t<00>|_dd<00>|D<>|_|rP|jrP|j<00>ndS)N<> _autoattachTcSsg|]}t|<00><00>qSr)r.)rzrurrrr~<00> s z2ColumnCollectionMixin.__init__.<locals>.<listcomp>)rIrr<><00>_pending_colargs<67> _check_attach)r#r<>rUr0rrrrZ<00> s    zColumnCollectionMixin.__init__ccs<>x<>|D]<5D>}d}d}t|t<00>s1|}n6g}tj|ii|jd6<>|rg|d}n|dk ry|n|}||||fVqWdS)Nr<4E>r)r<>rr <00>traverser<65>)rT<00> expressions<6E>expr<70>strnamer<65><00>cols<6C> add_elementrrr<00>"_extract_col_expression_collection<6F> s   z8ColumnCollectionMixin._extract_col_expression_collectionc
s<>dd<00><00>jD<>}dd<00>|D<>}t|<00>j|<00><00><00>r<>| sWtd<00><00>t<00>j<00>j|<00>}|s<><00><00>fdd<00>}<00><00>_x<00>D]}|j|<00>q<>WdSn|}tdd<00>|D<><00>}t|<00>dkr<><00>j|j<00><00>n<>t|<00>dkr<><01>j r<>|d j
<00><00>fd
d<00>|dd<00>D<>} | r<>t j d d j d d<00>| D<><00><00>jf<16><00>q<>ndS)NcSs%g|]}t|t<00>r|<00>qSr)r<>r<>)rzrurrrr~<00> s z7ColumnCollectionMixin._check_attach.<locals>.<listcomp>cSs(g|]}t|jt<00>r|<00>qSr)r<>r?r>)rzrurrrr~<00> s z#Should not reach here on event callcs*<00>j|<00><01>s&<00>jdd<00>ndS)NrnT)<02>discardr2)r<>r?)<02> cols_wo_tabler#rr<00> _col_attached<65> s z:ColumnCollectionMixin._check_attach.<locals>._col_attachedcSsg|]}|j<00>qSr)r?)rzrurrrr~<00> s rrcs%g|]}|j<00>k r|<00>qSr)r?)rzru)r?rrr~<00> s z(Column(s) %s are not part of table '%s'.z, css|]}d|VqdS)z'%s'Nr)rzrurrrr|<00> sz6ColumnCollectionMixin._check_attach.<locals>.<genexpr>)r1rc<00>
differencer<EFBFBD>Z_cols_wo_tabler<65>r<>r'rI<00>_allow_multiple_tablesr?rrKr<>r<>)
r#rnZcol_objsZ cols_w_tableZhas_string_colsr<r<>r<>rLZothersr)r;r#r?rr2<00> s0   #z#ColumnCollectionMixin._check_attachcCsJxC|jD]8}t|tj<00>r2|j|}n|jj|<00>q
WdS)N)r1r<>rr<>rur<>r<>)r#r?r<>rrrr<><00> sz!ColumnCollectionMixin._set_parent)
r6r7r8r<>r>rZ<00> classmethodr9r2r<>rrrrr/<00> s  -r/c@sjeZdZdZdd<00>Zdd<00>Zdd<00>Zdd <00>Zd
d <00>Zd d <00>Z dd<00>Z
dS)<11>ColumnCollectionConstraintz-A constraint that proxies a ColumnCollection.cOs<|jdd<00>}tj||<00>tj|d||<00>dS)aZ
:param \*columns:
A sequence of column names or Column objects.
:param name:
Optional, the in-database name of this constraint.
:param deferrable:
Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.
:param initially:
Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.
:param \**kw: other keyword arguments including dialect-specific
arguments are propagated to the :class:`.Constraint` superclass.
r0TN)rIr(rZr/)r#r<>rUr0rrrrZ
sz#ColumnCollectionConstraint.__init__cCs$tj||<00>tj||<00>dS)N)r(r<>r/)r#r?rrrr<>
sz&ColumnCollectionConstraint._set_parentcCs ||jkS)N)r<>)r#r<>rrr<00> __contains__#
sz'ColumnCollectionConstraint.__contains__cKs@|jd|jd|jd|j|jj<00><00>}|j|<00>S)Nrr<>r<>)rprr<>r<>r<>r<>r5)r#rUrurrrr2&
szColumnCollectionConstraint.copycCs|jj|<00>S)z<>Return True if this constraint contains the given column.
Note that this object also contains an attribute ``.columns``
which is a :class:`.ColumnCollection` of :class:`.Column` objects.
)r<><00>contains_column)r#r<>rrrrB+
sz*ColumnCollectionConstraint.contains_columncs&|jj<00><00>fdd<00><00>jD<>S)Nc3s|]}<00>|VqdS)Nr)rzrX)<01> ordered_dictrrr|:
sz6ColumnCollectionConstraint.__iter__.<locals>.<genexpr>)r<><00>_dataZ_list)r#r)rCr<00>__iter__5
s z#ColumnCollectionConstraint.__iter__cCst|jj<00>S)N)r<>r<>rD)r#rrr<00>__len__<
sz"ColumnCollectionConstraint.__len__N) r6r7r8r9rZr<>rAr2rBrErFrrrrr@
s     
r@c smeZdZdZdZdddddddd<00>fdd<00>Zdd<00>Zee<00>Zdd d
<00>Z<00>S) <0B>CheckConstraintzlA table- or column-level CHECK constraint.
Can be included in the definition of a Table or Column.
TNFc
s<>t|dd<00>|_g}
tj|jii|
jd6<>tt|<00>jd|d|d|d|d|d | d
||
<00>|d k r<>|j|<00>nd S) a<>Construct a CHECK constraint.
:param sqltext:
A string containing the constraint definition, which will be used
verbatim, or a SQL expression construct. If given as a string,
the object is converted to a :class:`.Text` object. If the textual
string includes a colon character, escape this using a backslash::
CheckConstraint(r"foo ~ E'a(?\:b|c)d")
:param name:
Optional, the in-database name of the constraint.
:param deferrable:
Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
issuing DDL for this constraint.
:param initially:
Optional string. If set, emit INITIALLY <value> when issuing DDL
for this constraint.
:param info: Optional data dictionary which will be populated into the
:attr:`.SchemaItem.info` attribute of this object.
.. versionadded:: 1.0.0
r<>Fr<46>rr<>r<>r)r-r<>r0N) r<00>sqltextr r3r<>rbrGrZr') r#rHrr<>r<>r?r-r)r0r<>r<>)rprrrZH
s    zCheckConstraint.__init__cCst|jt<00>rdSdSdS)NZcheck_constraintZcolumn_check_constraint)r<>r<>r>)r#rrrr:u
szCheckConstraint.__visit_name__c s<><00>dk r<<00><00>fdd<00>}tj<00>ji|<00>}n <00>j}t|d<00>jd<00>jd<00>jd<00>jd<00>dd d
<00>j<00>}<00>j |<00>S) Ncs+<00>jjj|<00>r#<00>j|jSdSdS)N)r?rurBrX)r<>)r#r<>rrr<>~
sz%CheckConstraint.copy.<locals>.replacerr<>r<>r)r?r0Fr<46>)
r Zreplacement_traverserHrGrr<>r<>r)r<>r5)r#r<>rUr<>rHrur)r#r<>rr2|
s        zCheckConstraint.copy) r6r7r8r9r>rZr:r;r2rr)rprrG@
s  +  rGc @s<>eZdZdZdZdddddddddddd<00>
Zdd<00>Zed d
<00><00>Zed d <00><00>Z ed d<00><00>Z
dd<00>Z edd<00><00>Z edd<00><00>Z dd<00>Zdddd<00>ZdS)r<>a<>A table-level FOREIGN KEY constraint.
Defines a single column or composite FOREIGN KEY ... REFERENCES
constraint. For a no-frills, single column foreign key, adding a
:class:`.ForeignKey` to the definition of a :class:`.Column` is a
shorthand equivalent for an unnamed, single column
:class:`.ForeignKeyConstraint`.
Examples of foreign key configuration are in :ref:`metadata_foreignkeys`.
Zforeign_key_constraintNFc  s<>tj<00>d|d|d|d| | <00>|<00>_|<00>_| <00>_|<00>_|
<00>_<00>fdd<00>|D<><00>_tj<00>|<00>| dk r<>t <00>d<00>r<>| <00>j
ks<>t <00>n<00>j | <00>ndS) a Construct a composite-capable FOREIGN KEY.
:param columns: A sequence of local column names. The named columns
must be defined and present in the parent Table. The names should
match the ``key`` given to each column (defaults to the name) unless
``link_to_name`` is True.
:param refcolumns: A sequence of foreign column names or Column
objects. The columns must all be located within the same Table.
:param name: Optional, the in-database name of the key.
:param onupdate: Optional string. If set, emit ON UPDATE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.
:param ondelete: Optional string. If set, emit ON DELETE <value> when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.
:param deferrable: Optional bool. If set, emit DEFERRABLE or NOT
DEFERRABLE when issuing DDL for this constraint.
:param initially: Optional string. If set, emit INITIALLY <value> when
issuing DDL for this constraint.
:param link_to_name: if True, the string name given in ``column`` is
the rendered name of the referenced column, not its locally assigned
``key``.
:param use_alter: If True, do not emit the DDL for this constraint as
part of the CREATE TABLE definition. Instead, generate it via an
ALTER TABLE statement issued after the full collection of tables
have been created, and drop it via an ALTER TABLE statement before
the full collection of tables are dropped.
The use of :paramref:`.ForeignKeyConstraint.use_alter` is
particularly geared towards the case where two or more tables
are established within a mutually-dependent foreign key constraint
relationship; however, the :meth:`.MetaData.create_all` and
:meth:`.MetaData.drop_all` methods will perform this resolution
automatically, so the flag is normally not needed.
.. versionchanged:: 1.0.0 Automatic resolution of foreign key
cycles has been added, removing the need to use the
:paramref:`.ForeignKeyConstraint.use_alter` in typical use
cases.
.. seealso::
:ref:`use_alter`
:param match: Optional string. If set, emit MATCH <value> when issuing
DDL for this constraint. Typical values include SIMPLE, PARTIAL
and FULL.
:param info: Optional data dictionary which will be populated into the
:attr:`.SchemaItem.info` attribute of this object.
.. versionadded:: 1.0.0
:param \**dialect_kw: Additional keyword arguments are dialect
specific, and passed in the form ``<dialectname>_<argname>``. See
the documentation regarding an individual dialect at
:ref:`dialect_toplevel` for detail on documented arguments.
.. versionadded:: 0.9.2
rr<>r<>r-cspg|]f}t|d<00>d<00>jd<00>jd<00>jd<00>jd<00>jd<00>jd<00>jd<00>j<00>j <00> <09>qS) r<>rr<>r<>r<>r<>r<>r<>r<>)
r<EFBFBD>rr<>r<>r<>r<>r<>r<>r<><00>dialect_kwargs)rzZrefcol)r#rrr~<00>
s z1ForeignKeyConstraint.__init__.<locals>.<listcomp>Nr<4E>) r(rZr<>r<>r<>r<>r<><00>elementsr/r<>r<>r<>r')r#r<>Z
refcolumnsrr<>r<>r<>r<>r<>r<>r<>r?r-r<>r)r#rrZ<00>
sJ
       zForeignKeyConstraint.__init__cCs$|jj|<00>|jj|<00>dS)N)r<>r<>rJr<>)r#r<>r<>rrrr sz$ForeignKeyConstraint._append_elementcCstjt|j|j<00><00>S)N)r<00> OrderedDict<63>zip<69> column_keysrJ)r#rrr<00> _elements szForeignKeyConstraint._elementscCs x|jD]
}|jSWdSdS)N)rJr<>)r#<00>elemrrrr<> sz%ForeignKeyConstraint._referred_schemacCs|jdjjS)a^The :class:`.Table` object to which this
:class:`.ForeignKeyConstraint` references.
This is a dynamically calculated attribute which may not be available
if the constraint and/or parent table is not yet associated with
a metadata collection that contains the referred table.
.. versionadded:: 1.0.0
r)rJr<>r?)r#rrr<00>referred_table s z#ForeignKeyConstraint.referred_tablecCs<>tdd<00>|jD<><00>}d|kr~t|<00>dkr~t|<00>dd<00>\}}tjd|j|j||f<16><00>ndS)NcSsg|]}|j<00><00>qSr)r<>)rzrOrrrr~- s z=ForeignKeyConstraint._validate_dest_table.<locals>.<listcomp>rrrzJForeignKeyConstraint on %s(%s) refers to multiple remote tables: %s and %s)rcrJr<>rwrrKrj<00>_col_description)r#r?Z
table_keysZelem0Zelem1rrrr, s z)ForeignKeyConstraint._validate_dest_tablecCs4t|d<00>r|jj<00>Sdd<00>|jD<>SdS)a<>Return a list of string keys representing the local
columns in this :class:`.ForeignKeyConstraint`.
This list is either the original string arguments sent
to the constructor of the :class:`.ForeignKeyConstraint`,
or if the constraint has been initialized with :class:`.Column`
objects, is the string .key of each element.
.. versionadded:: 1.0.0
r<>cSs4g|]*}t|t<00>r$|jn t|<00><00>qSr)r<>rrX<00>str)rzr<>rrrr~K s z4ForeignKeyConstraint.column_keys.<locals>.<listcomp>N)r<>r<>r<>r1)r#rrrrM: s   z ForeignKeyConstraint.column_keyscCsdj|j<00>S)Nz, )r<>rM)r#rrrrQO sz%ForeignKeyConstraint._col_descriptioncCs<>tj||<00>ytj||<00>WnHtk
rn}z(tjd|j|jdf<16><00>WYdd}~XnXxRt|j |j
<00>D];\}}t |d<00> s<>|j |k r<>|j |<00>q<>q<>W|j|<00>dS)NzQCan't create ForeignKeyConstraint on table '%s': no column named '%s' is present.rr<>)r(r<>r@<00>KeyErrorrrKr<>r(rLr<>rJr<>r<>r'r)r#r?Zker<65>r<>rrrr<>S s-"z ForeignKeyConstraint._set_parentc s<>tdd<00>|jD<><00><00>fdd<00>|jD<>d|jd|jd|jd|jd|jd |jd
|jd |j <00>}x0t
|j|j<00>D]\}}|j |<00>q<>W|j |<00>S) NcSsg|]}|jj<00>qSr)r<>rX)rzr<>rrrr~g s z-ForeignKeyConstraint.copy.<locals>.<listcomp>csXg|]N}|jd<00>d<00>dk rK|j<00>|jjjkrK<00>jnd<00><02>qS)rr<>N)r<>r<>r<>r?rXr)rzr<>)rr<>rrr~h s rr<>r<>r<>r<>r<>r<>r<>) r<>rJrr<>r<>r<>r<>r<>r<>r<>rLr5)r#rr<>rUr{Zself_fkZother_fkr)rr<>rr2e s"         zForeignKeyConstraint.copy)r6r7r8r9r:rZrr;rNr<>rPrrMrQr<>r2rrrrr<><00>
s   j   r<>csFeZdZdZdZ<00>fdd<00>Zdd<00>Zdd<00>Z<00>S) rga<> A table-level PRIMARY KEY constraint.
The :class:`.PrimaryKeyConstraint` object is present automatically
on any :class:`.Table` object; it is assigned a set of
:class:`.Column` objects corresponding to those marked with
the :paramref:`.Column.primary_key` flag::
>>> my_table = Table('mytable', metadata,
... Column('id', Integer, primary_key=True),
... Column('version_id', Integer, primary_key=True),
... Column('data', String(50))
... )
>>> my_table.primary_key
PrimaryKeyConstraint(
Column('id', Integer(), table=<mytable>,
primary_key=True, nullable=False),
Column('version_id', Integer(), table=<mytable>,
primary_key=True, nullable=False)
)
The primary key of a :class:`.Table` can also be specified by using
a :class:`.PrimaryKeyConstraint` object explicitly; in this mode of usage,
the "name" of the constraint can also be specified, as well as other
options which may be recognized by dialects::
my_table = Table('mytable', metadata,
Column('id', Integer),
Column('version_id', Integer),
Column('data', String(50)),
PrimaryKeyConstraint('id', 'version_id',
name='mytable_pk')
)
The two styles of column-specification should generally not be mixed.
An warning is emitted if the columns present in the
:class:`.PrimaryKeyConstraint`
don't match the columns that were marked as ``primary_key=True``, if both
are present; in this case, the columns are taken strictly from the
:class:`.PrimaryKeyConstraint` declaration, and those columns otherwise
marked as ``primary_key=True`` are ignored. This behavior is intended to
be backwards compatible with previous behavior.
.. versionchanged:: 0.9.2 Using a mixture of columns within a
:class:`.PrimaryKeyConstraint` in addition to columns marked as
``primary_key=True`` now emits a warning if the lists don't match.
The ultimate behavior of ignoring those columns marked with the flag
only is currently maintained for backwards compatibility; this warning
may raise an exception in a future release.
For the use case where specific options are to be specified on the
:class:`.PrimaryKeyConstraint`, but the usual style of using
``primary_key=True`` flags is still desirable, an empty
:class:`.PrimaryKeyConstraint` may be specified, which will take on the
primary key column collection from the :class:`.Table` based on the
flags::
my_table = Table('mytable', metadata,
Column('id', Integer, primary_key=True),
Column('version_id', Integer, primary_key=True),
Column('data', String(50)),
PrimaryKeyConstraint(name='mytable_pk',
mssql_clustered=True)
)
.. versionadded:: 0.9.2 an empty :class:`.PrimaryKeyConstraint` may now
be specified for the purposes of establishing keyword arguments with
the constraint, independently of the specification of "primary key"
columns within the :class:`.Table` itself; columns marked as
``primary_key=True`` will be gathered into the empty constraint's
column collection.
Zprimary_key_constraintcsOtt|<00>j|<00>|j|k rT|jj|j<00>||_|jj|<00>ndd<00>|jD<>}|jr|rt |<00>t |jj
<00><00>krt j d|j djdd<00>|D<><00>djdd<00>|jD<><00>djdd<00>|jD<><00>f<16>g|dd<00><nx#|jD]}d |_d
|_qW|jj|<00>dS) NcSsg|]}|jr|<00>qSr)r<>)rzrurrrr~<00> s z4PrimaryKeyConstraint._set_parent.<locals>.<listcomp>z<>Table '%s' specifies columns %s as primary_key=True, not matching locally specified columns %s; setting the current primary key columns to %s. This warning may become an exception in a future releasez, css|]}d|jVqdS)z'%s'N)r)rzrurrrr|<00> sz3PrimaryKeyConstraint._set_parent.<locals>.<genexpr>css|]}d|jVqdS)z'%s'N)r)rzrurrrr|<00> scss|]}d|jVqdS)z'%s'N)r)rzrurrrr|<00> sTF)rbrgr<>r<>rer:r<>rur<>rc<00>valuesrr<>rr<>r<><00>extend)r#r?Z table_pksru)rprrr<><00> s& !$  z PrimaryKeyConstraint._set_parentcCs>x|D]}d|_qW|jj|<00>|j|j<00>dS)aDrepopulate this :class:`.PrimaryKeyConstraint` given
a set of columns.
Existing columns in the table that are marked as primary_key=True
are maintained.
Also fires a new event.
This is basically like putting a whole new
:class:`.PrimaryKeyConstraint` object on the parent
:class:`.Table` object without actually replacing the object.
The ordering of the given list of columns is also maintained; these
columns will be appended to the list of columns after any which
are already present.
TN)r<>r<>rUr'r?)r#r<>r<>rrr<00>_reload<61> s  zPrimaryKeyConstraint._reloadcCs|jj|<00>dS)N)r<>r<>)r#r<>rrrr<> szPrimaryKeyConstraint._replace)r6r7r8r9r:r<>rVr<>rr)rprrg s
H rgc@seZdZdZdZdS)r<>aA table-level UNIQUE constraint.
Defines a single column or composite UNIQUE constraint. For a no-frills,
single column constraint, adding ``unique=True`` to the ``Column``
definition is a shorthand equivalent for an unnamed, single column
UniqueConstraint.
Zunique_constraintN)r6r7r8r9r:rrrrr<>
s r<>c@speZdZdZdZdd<00>Zdd<00>Zedd<00><00>Zd d
d <00>Z d d d <00>Z
dd<00>Z d S)r<>a<> A table-level INDEX.
Defines a composite (one or more column) INDEX.
E.g.::
sometable = Table("sometable", metadata,
Column("name", String(50)),
Column("address", String(100))
)
Index("some_index", sometable.c.name)
For a no-frills, single column index, adding
:class:`.Column` also supports ``index=True``::
sometable = Table("sometable", metadata,
Column("name", String(50), index=True)
)
For a composite index, multiple columns can be specified::
Index("some_index", sometable.c.name, sometable.c.address)
Functional indexes are supported as well, typically by using the
:data:`.func` construct in conjunction with table-bound
:class:`.Column` objects::
Index("some_index", func.lower(sometable.c.name))
.. versionadded:: 0.8 support for functional and expression-based indexes.
An :class:`.Index` can also be manually associated with a :class:`.Table`,
either through inline declaration or using
:meth:`.Table.append_constraint`. When this approach is used, the names
of the indexed columns can be specified as strings::
Table("sometable", metadata,
Column("name", String(50)),
Column("address", String(100)),
Index("some_index", "name", "address")
)
To support functional or expression-based indexes in this form, the
:func:`.text` construct may be used::
from sqlalchemy import text
Table("sometable", metadata,
Column("name", String(50)),
Column("address", String(100)),
Index("some_index", text("lower(name)"))
)
.. versionadded:: 0.9.5 the :func:`.text` construct may be used to
specify :class:`.Index` expressions, provided the :class:`.Index`
is explicitly associated with the :class:`.Table`.
.. seealso::
:ref:`schema_indexes` - General information on :class:`.Index`.
:ref:`postgresql_indexes` - PostgreSQL-specific options available for
the :class:`.Index` construct.
:ref:`mysql_indexes` - MySQL-specific options available for the
:class:`.Index` construct.
:ref:`mssql_indexes` - MSSQL-specific options available for the
:class:`.Index` construct.
r<>c Os<>d|_g}x?|j|<00>D].\}}}}|dk r|j|<00>qqW||_t||jdd<00><00>|_|jdd<00>|_d|kr<>|jd<00>|_n|j |<00>t
j ||<00>dS)a~Construct an index object.
:param name:
The name of the index
:param \*expressions:
Column expressions to include in the index. The expressions
are normally instances of :class:`.Column`, but may also
be arbitrary SQL expressions which ultimately refer to a
:class:`.Column`.
:param unique=False:
Keyword only argument; if True, create a unique index.
:param quote=None:
Keyword only argument; whether to apply quoting to the name of
the index. Works in the same manner as that of
:paramref:`.Column.quote`.
:param info=None: Optional data dictionary which will be populated
into the :attr:`.SchemaItem.info` attribute of this object.
.. versionadded:: 1.0.0
:param \**kw: Additional keyword arguments not mentioned above are
dialect specific, and passed in the form
``<dialectname>_<argname>``. See the documentation regarding an
individual dialect at :ref:`dialect_toplevel` for detail on
documented arguments.
Nr0r<>Fr-) r?r9r<>r4rrIrr<>r-r<>r/rZ) r#rr4rUr<>r5r<>r6r8rrrrZc s     zIndex.__init__cCs<>tj||<00>|jdk rY||jk rYtjd|j|jj|jf<16><00>n||_|jj|<00>dd<00>t j
|j |j <00>D<>|_ dS)NzKIndex '%s' is against table '%s', and cannot be associated with table '%s'.cSs1g|]'\}}t|t<00>r'|n|<00>qSr)r<>r)rzr5Zcolexprrrrr~<00> s z%Index._set_parent.<locals>.<listcomp>) r/r<>r?rrKrr<>rdr<>r<00> zip_longestr4r<>)r#r?rrrr<><00> s    zIndex._set_parentcCs
|jjS)z2Return the connectable associated with this Index.)r?rt)r#rrrrt<00> sz
Index.bindNcCs2|dkrt|<00>}n|jtj|<00>|S)z<>Issue a ``CREATE`` statement for this
:class:`.Index`, using the given :class:`.Connectable`
for connectivity.
.. seealso::
:meth:`.MetaData.create_all`.
N)r r<>rr<>)r#rtrrrr<><00> s
z Index.createcCs2|dkrt|<00>}n|jtj|<00>dS)z<>Issue a ``DROP`` statement for this
:class:`.Index`, using the given :class:`.Connectable`
for connectivity.
.. seealso::
:meth:`.MetaData.drop_all`.
N)r r<>rr<>)r#rtrrrr<><00> s
z
Index.dropcCsGddjt|j<00>gdd<00>|jD<>|jr>dgpAg<17>S)Nz Index(%s)z, cSsg|]}t|<00><00>qSr)r<>)rz<00>errrr~<00> s z"Index.__repr__.<locals>.<listcomp>z unique=True)r<>r<>rr4r<>)r#rrrr/<00> s#zIndex.__repr__) r6r7r8r9r:rZr<>r;rtr<>r<>r/rrrrr<> s I 3 r<>zix_%(column_0_label)s<>ixc@sHeZdZdZdZddddeddd<00>ZdZdd<00>Zd d
<00>Z d d <00>Z
d d<00>Z dd<00>Z dd<00>Z dd<00>Zdd<00>Zejd<00>dd<00><00>Zeee<00>Zdd<00>Zdd<00>Zedd<00><00>Zdddddd d!d"<00>Zd#d$<00>Zddd d%d&<00>Zddd d'd(<00>ZdS))<29>MetaDataa<61>A collection of :class:`.Table` objects and their associated schema
constructs.
Holds a collection of :class:`.Table` objects as well as
an optional binding to an :class:`.Engine` or
:class:`.Connection`. If bound, the :class:`.Table` objects
in the collection and their columns may participate in implicit SQL
execution.
The :class:`.Table` objects themselves are stored in the
:attr:`.MetaData.tables` dictionary.
:class:`.MetaData` is a thread-safe object for read operations.
Construction of new tables within a single :class:`.MetaData` object,
either explicitly or via reflection, may not be completely thread-safe.
.. seealso::
:ref:`metadata_describing` - Introduction to database metadata
rVNFcCs<>tj<00>|_t||<00>|_||_|r<||_nt<00>|_i|_ t
j t <00>|_ ||_|r<>tjd<00>|s<>tjd<00><00>n|j<00>ndS)a<>Create a new MetaData object.
:param bind:
An Engine or Connection to bind to. May also be a string or URL
instance, these are passed to create_engine() and this MetaData will
be bound to the resulting engine.
:param reflect:
Optional, automatically load all tables from the bound database.
Defaults to False. ``bind`` is required when this option is set.
.. deprecated:: 0.8
Please use the :meth:`.MetaData.reflect` method.
:param schema:
The default schema to use for the :class:`.Table`,
:class:`.Sequence`, and potentially other objects associated with
this :class:`.MetaData`. Defaults to ``None``.
When this value is set, any :class:`.Table` or :class:`.Sequence`
which specifies ``None`` for the schema parameter will instead
have this schema name defined. To build a :class:`.Table`
or :class:`.Sequence` that still has ``None`` for the schema
even when this parameter is present, use the :attr:`.BLANK_SCHEMA`
symbol.
.. seealso::
:paramref:`.Table.schema`
:paramref:`.Sequence.schema`
:param quote_schema:
Sets the ``quote_schema`` flag for those :class:`.Table`,
:class:`.Sequence`, and other objects which make usage of the
local ``schema`` name.
:param info: Optional data dictionary which will be populated into the
:attr:`.SchemaItem.info` attribute of this object.
.. versionadded:: 1.0.0
:param naming_convention: a dictionary referring to values which
will establish default naming conventions for :class:`.Constraint`
and :class:`.Index` objects, for those objects which are not given
a name explicitly.
The keys of this dictionary may be:
* a constraint or Index class, e.g. the :class:`.UniqueConstraint`,
:class:`.ForeignKeyConstraint` class, the :class:`.Index` class
* a string mnemonic for one of the known constraint classes;
``"fk"``, ``"pk"``, ``"ix"``, ``"ck"``, ``"uq"`` for foreign key,
primary key, index, check, and unique constraint, respectively.
* the string name of a user-defined "token" that can be used
to define new naming tokens.
The values associated with each "constraint class" or "constraint
mnemonic" key are string naming templates, such as
``"uq_%(table_name)s_%(column_0_name)s"``,
which describe how the name should be composed. The values
associated with user-defined "token" keys should be callables of the
form ``fn(constraint, table)``, which accepts the constraint/index
object and :class:`.Table` as arguments, returning a string
result.
The built-in names are as follows, some of which may only be
available for certain types of constraint:
* ``%(table_name)s`` - the name of the :class:`.Table` object
associated with the constraint.
* ``%(referred_table_name)s`` - the name of the :class:`.Table`
object associated with the referencing target of a
:class:`.ForeignKeyConstraint`.
* ``%(column_0_name)s`` - the name of the :class:`.Column` at
index position "0" within the constraint.
* ``%(column_0_label)s`` - the label of the :class:`.Column` at
index position "0", e.g. :attr:`.Column.label`
* ``%(column_0_key)s`` - the key of the :class:`.Column` at
index position "0", e.g. :attr:`.Column.key`
* ``%(referred_column_0_name)s`` - the name of a :class:`.Column`
at index position "0" referenced by a
:class:`.ForeignKeyConstraint`.
* ``%(constraint_name)s`` - a special key that refers to the
existing name given to the constraint. When this key is
present, the :class:`.Constraint` object's existing name will be
replaced with one that is composed from template string that
uses this token. When this token is present, it is required that
the :class:`.Constraint` is given an expicit name ahead of time.
* user-defined: any additional token may be implemented by passing
it along with a ``fn(constraint, table)`` callable to the
naming_convention dictionary.
.. versionadded:: 0.9.2
.. seealso::
:ref:`constraint_naming_conventions` - for detailed usage
examples.
z;reflect=True is deprecate; please use the reflect() method.z8A bind must be supplied in conjunction with reflect=TrueN)r<00> immutabledictrLrr<00>naming_conventionr-rc<00>_schemasr!<00> collections<6E> defaultdictr<74>r<>rtrJrrK<00>reflect)r#rtr`rrYr\r-rrrrZ<00> ss       zMetaData.__init__cCs d|jS)NzMetaData(bind=%r))rt)r#rrrr/<00> szMetaData.__repr__cCs+t|tj<00>s|j}n||jkS)N)r<>rr<>rXrL)r#Z table_or_keyrrrrA<00> s zMetaData.__contains__cCsBt||<00>}tj|j||<00>|r>|jj|<00>ndS)N)r<00>dict<63> __setitem__rLr]r<>)r#rrr?rXrrrrP<00> szMetaData._add_tablecCs<>t||<00>}tj|j|d<00>}|dk rWx!|jD]}|j|<00>q=Wn|jr<>tdd<00>|jj<00>D<><00>|_ndS)NcSs(g|]}|jdk r|j<00>qS)N)r)rz<00>trrrr~<00> s z*MetaData._remove_table.<locals>.<listcomp>) rrarIrLrhrr]rcrT)r#rrrX<00>removedr<64>rrrrS<00> s   zMetaData._remove_tablecCs@i|jd6|jd6|jd6|jd6|jd6|jd6S)NrLr<00>schemas<61> sequences<65>fk_memosr\)rLrr]r!r<>r\)r#rrr<00> __getstate__<5F> s  



zMetaData.__getstate__cCs[|d|_|d|_|d|_d|_|d|_|d|_|d|_dS)NrLrr\rfrerg)rLrr\<00>_bindr!r]r<>)r#<00>staterrr<00> __setstate__<5F> s      zMetaData.__setstate__cCs |jdk S)z:True if this MetaData is bound to an Engine or Connection.N)ri)r#rrr<00>is_bound<6E> szMetaData.is_boundcCs|jS)a An :class:`.Engine` or :class:`.Connection` to which this
:class:`.MetaData` is bound.
Typically, a :class:`.Engine` is assigned to this attribute
so that "implicit execution" may be used, or alternatively
as a means of providing engine binding information to an
ORM :class:`.Session` object::
engine = create_engine("someurl://")
metadata.bind = engine
.. seealso::
:ref:`dbengine_implicit` - background on "bound metadata"
)ri)r#rrrrt<00> sz MetaData.bindzsqlalchemy.engine.urlcCs>t|tj|jf<17>r1tj|<00>|_n ||_dS)z;Bind this MetaData to an Engine, Connection, string or URL.N)r<>rr<><00>URL<52>
sqlalchemy<EFBFBD> create_engineri)r#<00>urlrtrrr<00>_bind_to<74> szMetaData._bind_tocCs.tj|j<00>|jj<00>|jj<00>dS)z+Clear all Table objects from this MetaData.N)ra<00>clearrLr]r<>)r#rrrrr<00> s zMetaData.clearcCs|j|j|j<00>dS)z1Remove the given Table object from this MetaData.N)rSrr)r#r?rrrr<00> szMetaData.removecCs(tjt|jj<00>ddd<00><00><01>S)a<>Returns a list of :class:`.Table` objects sorted in order of
foreign key dependency.
The sorting will place :class:`.Table` objects that have dependencies
first, before the dependencies themselves, representing the
order in which they can be created. To get the order in which
the tables would be dropped, use the ``reversed()`` Python built-in.
.. warning::
The :attr:`.sorted_tables` accessor cannot by itself accommodate
automatic resolution of dependency cycles between tables, which
are usually caused by mutually dependent foreign key constraints.
To resolve these cycles, either the
:paramref:`.ForeignKeyConstraint.use_alter` parameter may be appled
to those constraints, or use the
:func:`.schema.sort_tables_and_constraints` function which will break
out foreign key constraints involved in cycles separately.
.. seealso::
:func:`.schema.sort_tables`
:func:`.schema.sort_tables_and_constraints`
:attr:`.MetaData.tables`
:meth:`.Inspector.get_table_names`
:meth:`.Inspector.get_sorted_table_and_fkc_names`
rXcSs|jS)N)rX)rcrrrrvsz(MetaData.sorted_tables.<locals>.<lambda>)rZ sort_tablesrwrLrT)r#rrr<00> sorted_tables<65> s#zMetaData.sorted_tablesTc s1|dkrt<00><00>}n|j<00><00>}idd6|d6<>d6|d6} | j|<00><01>dkrq<00>j<00>n<00>dk r<><00>| d<ntj|jj<00>d|<00><01><00>|r<><00>j|jj |<00><00><00>n<00>dk rtj<00>fd d
<00><00>D<><00>}
n<00>}
t
<00>j <00><00><00>dkrJ<01><00>fd d
<00>t <00>|
<00>D<>} n<>tj <00><00>r<><01><00><00><00>fd d
<00>t <00>|
<00>D<>} n<00>fd d
<00><00>D<>} | r<><01>r<>d<00>p<>d} tjd|jj| dj| <00>f<16><00>n<00><00>fdd
<00><00>D<>} x| D]}t|<00>| <00>q WWdQXdS)aL Load all available table definitions from the database.
Automatically creates ``Table`` entries in this ``MetaData`` for any
table available in the database but not yet present in the
``MetaData``. May be called multiple times to pick up tables recently
added to the database, however no special action is taken if a table
in this ``MetaData`` no longer exists in the database.
:param bind:
A :class:`.Connectable` used to access the database; if None, uses
the existing bind on this ``MetaData``, if any.
:param schema:
Optional, query and reflect tables from an alterate schema.
If None, the schema associated with this :class:`.MetaData`
is used, if any.
:param views:
If True, also reflect views.
:param only:
Optional. Load only a sub-set of available named tables. May be
specified as a sequence of names or a callable.
If a sequence of names is provided, only those tables will be
reflected. An error is raised if a table is requested but not
available. Named tables already present in this ``MetaData`` are
ignored.
If a callable is provided, it will be used as a boolean predicate to
filter the list of potential table names. The callable is called
with a table name and this ``MetaData`` instance as positional
arguments and should return a true value for any table to reflect.
:param extend_existing: Passed along to each :class:`.Table` as
:paramref:`.Table.extend_existing`.
.. versionadded:: 0.9.1
:param autoload_replace: Passed along to each :class:`.Table` as
:paramref:`.Table.autoload_replace`.
.. versionadded:: 0.9.1
:param \**dialect_kwargs: Additional keyword arguments not mentioned
above are dialect specific, and passed in the form
``<dialectname>_<argname>``. See the documentation regarding an
individual dialect at :ref:`dialect_toplevel` for detail on
documented arguments.
.. versionadded:: 0.9.2 - Added
:paramref:`.MetaData.reflect.**dialect_kwargs` to support
dialect-level reflection options for all :class:`.Table`
objects reflected.
NTr\r[rAr]rr$cs g|]}d<00>|f<16>qS)z%s.%sr)rzr)rrrr~`s z$MetaData.reflect.<locals>.<listcomp>cs.g|]$\}}<00>s$|<00>kr|<00>qSrr)rzr<00>schname)<02>currentrArrr~hs cs=g|]3\}}<00>s$|<00>kr<00>|<00><00>r|<00>qSrr)rzrrt)rurA<00>onlyr#rrr~ls cs"g|]}|<00>kr|<00>qSrr)rzr)<01> availablerrr~qs z schema '%s'r<>zACould not reflect: requested table(s) not available in %s%s: (%s)z, cs(g|]}<00>s|<00>kr|<00>qSrr)rzr)rurArrr~xs )r <00>connectr$rrZ
OrderedSetZengineZ table_namesrrZget_view_namesrcrLrLr rrNrpr<>r>)r#rtrZviewsrvrAr]rI<00>connZ reflect_optsZavailable_w_schema<6D>load<61>missing<6E>srr)rwrurArvrr#rr`sL< 
       % zMetaData.reflectcs9<00>fdd<00>}tj|d|jdd<00>|<00>dS)z}Append a DDL event listener to this ``MetaData``.
.. deprecated:: 0.7
See :class:`.DDLEvents`.
cs$|d}<00>t||d|<00>dS)NrL)r)r<>r$rUrL)r<>rrr<><00>s
z4MetaData.append_ddl_listener.<locals>.adapt_listenerr<72>r<>r<>N)rrkr<>)r#r<>r<>r<>r)r<>rr<>~szMetaData.append_ddl_listenercCs>|dkrt|<00>}n|jtj|d|d|<00>dS)ayCreate all tables stored in this metadata.
Conditional by default, will not attempt to recreate tables already
present in the target database.
:param bind:
A :class:`.Connectable` used to access the
database; if None, uses the existing bind on this ``MetaData``, if
any.
:param tables:
Optional list of ``Table`` objects, which is a subset of the total
tables in the ``MetaData`` (others are ignored).
:param checkfirst:
Defaults to True, don't issue CREATEs for tables already present
in the target database.
Nr<4E>rL)r r<>rr<>)r#rtrLr<>rrr<00>
create_all<EFBFBD>s   zMetaData.create_allcCs>|dkrt|<00>}n|jtj|d|d|<00>dS)atDrop all tables stored in this metadata.
Conditional by default, will not attempt to drop tables not present in
the target database.
:param bind:
A :class:`.Connectable` used to access the
database; if None, uses the existing bind on this ``MetaData``, if
any.
:param tables:
Optional list of ``Table`` objects, which is a subset of the
total tables in the ``MetaData`` (others are ignored).
:param checkfirst:
Defaults to True, only issue DROPs for tables confirmed to be
present in the target database.
Nr<4E>rL)r r<>rr<>)r#rtrLr<>rrr<00>drop_all<6C>s   zMetaData.drop_all)r6r7r8r9r:<00>DEFAULT_NAMING_CONVENTIONrZrLr/rArPrSrhrkrlrtrr"rqr;rrrrsr`r<>r}r~rrrrrZ<00> s4  <0F>       % t rZcs|eZdZdZdZ<00>fdd<00>Zdd<00>Zejd<00>dd <00><00>Z e
ee <00>Zd
d <00>Z d d <00>Z <00>S)<0E>ThreadLocalMetaDataaA MetaData variant that presents a different ``bind`` in every thread.
Makes the ``bind`` property of the MetaData a thread-local value, allowing
this collection of tables to be bound to different ``Engine``
implementations or connections in each thread.
The ThreadLocalMetaData starts off bound to None in each thread. Binds
must be made explicitly by assigning to the ``bind`` property or using
``connect()``. You can also re-bind dynamically multiple times per
thread, just like a regular ``MetaData``.
rVcs2tjj<00>|_i|_tt|<00>j<00>dS)z Construct a ThreadLocalMetaData.N)r<00> threading<6E>local<61>context<78>_ThreadLocalMetaData__enginesrbr<>rZ)r#)rprrrZ<00>s zThreadLocalMetaData.__init__cCst|jdd<00>S)z<>The bound Engine or Connection for this thread.
This property may be assigned an Engine or Connection, or assigned a
string or URL to automatically create a basic Engine for this bind
with ``create_engine()``.<2E>_engineN)r<>r<>)r#rrrrt<00>szThreadLocalMetaData.bindzsqlalchemy.engine.urlc Cs<>t|tj|jf<17>rsy|j||j_Wq<57>tk
rotj |<00>}||j|<||j_Yq<59>Xn+||jkr<>||j|<n||j_dS)z-Bind to a Connectable in the caller's thread.N)
r<EFBFBD>rr<>rmr<>r<>r<>rSrnro)r#rprtrXrrrrq<00>s  zThreadLocalMetaData._bind_tocCs"t|jd<00>o!|jjdk S)z(True if there is a bind for this thread.r<>N)r<>r<>r<>)r#rrrrl<00>szThreadLocalMetaData.is_boundcCs:x3|jj<00>D]"}t|d<00>r|j<00>qqWdS)z2Dispose all bound engines, in all thread contexts.<2E>disposeN)r<>rTr<>r<>)r#rXrrrr<><00>szThreadLocalMetaData.dispose) r6r7r8r9r:rZrtrr"rqr;rlr<>rr)rprr<><00>s   r<>)@r9<00>
__future__r<00>inspectr<74>rrrr<00>baser r
r r r rrJrrrrrrrrrr<>rr^rnr<00>types<65>symbolr<6C>rHrZ_self_inspectsZ Visitabler r>r<>r<>rCrrr<>r<>r<>r<>r'r(r-r.r/r@rGr<>rgr<>r<>r[rrZr<>rrrr<00><module>sh "@     4<1C><00><00><19><00>*<19><00>
!i<16>2%O  X<Q<16><16> <1C>  <16><00>