!TwĜ,dZddlmZddlZddlZddlZddlmZddlmZddlm Z ddl m Z dd l m Z dd l m Z dd l mZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZejdZejddZ dZ!dZ"ej#Gdd ee j$Z%Gd!d"e e%eZ&Gd#d$e e%eZ'Gd%d&e e%Z(Gd'd(e)Z*Gd)d*e*e%Z+Gd+d,e+Z,Gd-d.e)Z-Gd/d0e-e+Z.ej#Gd1d2e*eZ/Gd3d4e/Z0ej1d5d6Gd7d8e0Z2Gd9d:e e%Z3d;Z4d<Z5Gd=d>e)Z6Gd?d@e6e3Z7GdAdBe7Z8GdCdDe7Z9GdEdFe7Z:GdGdHe7Z;GdIdJe e6e%Z<ej=dKdLiZ>GdMdNe%Z?GdOdPe?Z@GdQdRe)ZAeAdZBeAjCZCGdSdTe/e%ZDdS)Ua/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. )absolute_importN)ddl)type_api)visitors)_bind_or_error)ColumnCollection) DialectKWArgs)SchemaEventTarget) _as_truncated)_document_text_coercion)_literal_as_text) ClauseElement) ColumnClause) ColumnElement) quoted_name) TextClause) TableClauseevent)exc) inspection)util retain_schema blank_schemazSymbol indicating that a :class:`_schema.Table` or :class:`.Sequence` should have 'None' for its schema, even if the parent :class:`_schema.MetaData` has specified a schema. .. versionadded:: 1.0.14 c||S|dz|zS)N.)nameschemas /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py_get_table_keyr#Is ~ |d""cJ|Sfd}tj|i|S)Nct|tr)|jur |jjvrj|jSdSN) isinstanceColumntablekeyc)col source_table target_tables r"replacez!_copy_expression..replaceVsE sF # #  \))<>))>#'* *4r$)rreplacement_traverse) expressionr.r/r0s `` r"_copy_expressionr3RsJ|3  (R A AAr$ceZdZdZdZdZdZdZee j dddZ e j d Z d Zd Zd S) SchemaItemz3Base class for items that define a database schema. schema_itemc|D]Z}|V |j}||#t$r5}tjt jd|z|Yd}~Rd}~wwxYw[dS)z7Initialize the list of child items for this SchemaItem.NzJ'SchemaItem' object, such as a 'Column' or a 'Constraint' expected, got %r)replace_context)_set_parent_with_dispatchAttributeErrorrraise_r ArgumentError)selfargsitemspwderrs r" _init_itemszSchemaItem._init_itemsis  D 9DDJJJJ&K)<>BC),    s A+AAc gS)z"used to allow SchemaVisitor accessrr=kwargss r" get_childrenzSchemaItem.get_children{s r$c0tj|dgS)Ninfo) omit_kwargr generic_reprr=s r"__repr__zSchemaItem.__repr__s 6(;;;;r$0.9zThe :attr:`.SchemaItem.quote` attribute is deprecated and will be removed in a future release. Use the :attr:`.quoted_name.quote` attribute on the ``name`` field of the target schema item to retrievequoted status.c|jjS)zReturn the value of the ``quote`` flag passed to this schema object, for those schema items which have a ``name`` field. )r quoterLs r"rPzSchemaItem.quotesyr$ciS)aZInfo 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:`_schema.Table` and :class:`_schema.Column`. rrLs r"rHzSchemaItem.infos  r$cd|jvr|j|_|j|j|S)NrH)__dict__rHcopydispatch_update)r=r6s r"_schema_item_copyzSchemaItem._schema_item_copysB T] " "#y~~//K $$T]333r$c.|||Sr')get)r=effective_schemamap_s r"_translate_schemazSchemaItem._translate_schemasxx(*:;;;r$N)__name__ __module__ __qualname____doc____visit_name__rBrFrMpropertyr deprecatedrPmemoized_propertyrHrWr\rr$r"r5r5cs=="N$<<<T_  X     <<<<, )`` 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:`_schema.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:`_schema.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:`_schema.MetaData` of this :class:`_schema.Table` specifies its own :paramref:`_schema.MetaData.schema` parameter, then that schema name will be applied to this :class:`_schema.Table` if the schema parameter here is set to ``None``. To set a blank schema name on a :class:`_schema.Table` that would otherwise use the schema set on the owning :class:`_schema.MetaData`, specify the special symbol :attr:`.BLANK_SCHEMA`. .. versionadded:: 1.0.14 Added the :attr:`.BLANK_SCHEMA` symbol to allow a :class:`_schema.Table` to have a blank schema name even when the parent :class:`_schema.MetaData` specifies :paramref:`_schema.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: the same as :paramref:`_schema.Table.extend_existing`. :param comment: Optional string that will render an SQL comment on table creation. .. versionadded:: 1.2 Added the :paramref:`_schema.Table.comment` parameter to :class:`_schema.Table`. :param \**kw: Additional keyword arguments not mentioned above are dialect specific, and passed in the form ``_``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. r*)0.7zThe :paramref:`_schema.Table.useexisting` parameter is deprecated and will be removed in a future release. Please use :paramref:`_schema.Table.extend_existing`.) useexistingc|st|S |d|d|dd}}}n#t$rtdwxYw|dd}||j}n |t urd}|dd}|dd}d |vr.|rd }tj ||d d}|r|rd }tj ||d d} t||} | |j vrH|s(|s&t|rtj d | z|j | } |r | j|i|| S| rtj d| zt|} | j| |||||  | j||g|Ri|| j| || S#t)j5|||dddYdS#1swxYwYYdSxYw)Nrrrz$Table() takes at least two argumentsr! keep_existingFextend_existingrhz/useexisting is synonymous with extend_existing.z9keep_existing and extend_existing are mutually exclusive. mustexistzTable '%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)object__new__ IndexError TypeErrorrYr! BLANK_SCHEMApoprr<r#tablesboolInvalidRequestError_init_existingrUbefore_parent_attach _add_table_initafter_parent_attachr safe_reraise _remove_table) clsr>kwr metadatar!rjrkmsgrlr+r*s r"rnz Table.__new__s '>>#&& & D#'7DGT!""XD(DD D D DBCC C D$'' >_FF | # #F66 &&!2E:: B   -G',,, ff]E::O  )_ )MC#C(( (FF;.. T6** (/ ! !   T$ZZ --03 3OC(E 2$$d1b111L P-.F#.NOOONN3''E N / /x @ @ @   fe 4 4 4 9 D(8T888R888225(CCC  9&((99**488899999999999999999999s99A.HI H?1 I ?I I I I rNzThe :meth:`.SchemaItem.quote` method is deprecated and will be removed in a future release. Use the :attr:`.quoted_name.quote` attribute on the ``schema`` field of the target schema item to retrieve quoted status.c|jjS)zeReturn the value of the ``quote_schema`` flag passed to this :class:`_schema.Table`. )r!rPrLs r" quote_schemazTable.quote_schema5s{  r$cdS)zConstructor 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>r~s r"__init__zTable.__init__Dsr$c tt|t||dd||_|dd|_|j |j|_nF|jturd|_n0|dd}t|j||_t|_ t|_ t|_ td|t|_t|_|j|jd|j|_n |j|_|dd}|d|du}|d d|d d}|d d} |d d} |d d|_|dd|_d|vr|d|_d|vr3|d} | D]\} } t-j|| | |dg|_|jdi||r|||| || |j|dS)NrPr!rT)_implicit_generatedr autoload_withautoloadautoload_replace _extend_on resolve_fksinclude_columnsimplicit_returningcommentrH listenersprefixes)rrr)superrfrrrrrr!rqsetindexes constraintsr _columnsPrimaryKeyConstraintr9 foreign_keys_extra_dependenciesr fullnamerrrHrlisten _prefixes _extra_kwargs _autoloadrB)r=r rr>rErrrrrrrevtfn __class__s r"ryz Table._initOs eT## fjj$77 8 8   ! jj400 ; "/DKK [L ( (DKK!::nd;;L%dk<@@DKuu 55(**  $   # #D ) ) )EE#&55 ; "'+{{{DII>DMM IDM ?D99 ::j-t*CDD %t,,,ZZ d33 jj55  **%6=="(**-A4"H"Hzz)T22 V   6**DI &  ;//I$ , ,R T3++++J33$$V$$$   NN%'     $r$rTNc|r'||jj|||||dSt|d}||jj|||||dS)NrzNo engine is bound to this Table's MetaData. Pass an engine to the Table via autoload_with=, or associate the MetaData with an engine via metadata.bind=)r) run_callabledialect reflecttabler)r=rrrexclude_columnsrrbinds r"rzTable._autoloads    & &%2% '     "-D    )%      r$c0t|jdS)zTReturn the set of constraints as a list, sorted by creation order. c|jSr')_creation_order)r,s r"z+Table._sorted_constraints..s a6Gr$r+)sortedrrLs r"_sorted_constraintszTable._sorted_constraintss d&,G,GHHHHr$c>td|jDS)a :class:`_schema.ForeignKeyConstraint` objects referred to by this :class:`_schema.Table`. This list is produced from the collection of :class:`_schema.ForeignKey` objects currently associated. .. versionadded:: 1.0.0 c3$K|] }|jV dSr') constraint).0fkcs r" z0Table.foreign_key_constraints..s$??c3>??????r$)rrrLs r"foreign_key_constraintszTable.foreign_key_constraintss$??T->??????r$c@|dd}|d|du}|dd}|dd}|dd}|r'||jkrtjd|j|f|dd}|d d} |-|jD]%} | j|vr|j| &d D]} | |vrtjd d |vr|d d|_d |vr|d |_ |r6|sd|jD} nd} | |j ||| | ||j di||j |dS)NrrrTr!rz7Can't change schema of existing table from '%s' to '%s'rr)rPrz2Can't redefine 'quote' or 'quote_schema' argumentsrrHcg|] }|j Srr rr,s r" z(Table._init_existing..s":":":a16":":":r$rr)rrr!rr<r,r rremoverrHrrrrB) r=r>rErrrr!rrrr,r+rs r"rvzTable._init_existings ?D99 ::j-t*CDD!::&8$??Hd++ZZ d33  f ++#If%  !**%6==jj55  &V , ,600M((+++,  Cf}}'H   !::i66DL V   6**DI  # %#;":46":":":"$ NN %     $$V$$$$r$c 0||dSr'_validate_dialect_kwargsrDs r"rzTable._extra_kwargs %%f-----r$cdSr'rrLs r"_init_collectionszTable._init_collections r$cdSr'rrLs r"_reset_exportedzTable._reset_exported rr$c|jjSr') primary_key_autoincrement_columnrLs r"rzTable._autoincrement_column s55r$c6t|j|jS)aReturn the 'key' for this :class:`_schema.Table`. This value is used as the dictionary key within the :attr:`_schema.MetaData.tables` collection. It is typically the same as that of :attr:`_schema.Table.name` for a table with no :attr:`_schema.Table.schema` set; otherwise it is typically of the form ``schemaname.tablename``. )r#r r!rLs r"r+z Table.keysdi555r$cddtjgtjgzdjDzfddDzzS)Nz Table(%s), c,g|]}t|Srreprrxs r"rz"Table.__repr__..#s---1tAww---r$c Tg|]$}|dtt|%S=rgetattrrkr=s r"rz"Table.__repr__..$s7III!!!T'$"2"23334IIIr$r!)joinrr rcolumnsrLs`r"rMzTable.__repr__s{TYY $)__ DM""# $-- --- .JIIIjIII J    r$c6t|j|jSr')r# descriptionr!rLs r"__str__z Table.__str__'sd. <<s( ((.....r$c0||dS)aAppend 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. Nr)r=rs r"append_constraintzTable.append_constraintTs& ,,T22222r$rgzthe :meth:`_schema.Table.append_ddl_listener` method is deprecated and will be removed in a future release. Please refer to :class:`.DDLEvents`.cpfd}tj|dddz|dS)z.Append a DDL event listener to this ``Table``.c"||dSr'r)target connectionr~ event_namelisteners r"adapt_listenerz1Table.append_ddl_listener..adapt_listenerss HZ 4 4 4 4 4r$-_Nrrr0r=rrrs `` r"append_ddl_listenerzTable.append_ddl_listenerisS 5 5 5 5 5 5  T2 2 23 < <} | jr t-| jg fd| jDR| j d| j ? S)a Return a copy of this :class:`_schema.Table` associated with a different :class:`_schema.MetaData`. E.g.:: m1 = MetaData() user = Table('user', m1, Column('id', Integer, primary_key=True)) m2 = MetaData() user_copy = user.tometadata(m2) :param metadata: Target :class:`_schema.MetaData` object, into which the new :class:`_schema.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:`_schema.Table`. If set to a string name, the new :class:`_schema.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:`_schema.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:`_schema.ForeignKeyConstraint`. The callable accepts this parent :class:`_schema.Table`, the target schema that we are changing to, the :class:`_schema.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:`_schema.Table` to be copied to the same :class:`_schema.MetaData` target with a new name. .. versionadded:: 1.0.0 NzBTable '%s' already exists within the given MetaData - not copying.r)r!r)r!r/c2g|]}t|Sr)r3)rexprr=r*s r"rz$Table.tometadata..4s5%T477r$)unique_table)r RETAIN_SCHEMAr!r#rsrwarnrrappendrTrfrrErr(ForeignKeyConstraint_referred_schemar _type_bound _column_flagrIndex expressionsrrW) r=rr!referred_schema_fnr r+r>r,referred_schemafk_constraint_schemaindexr*s ` @r" tometadatazTable.tometadatasX <9D ] " "[FF ^_FT6** (/ ! ! I*,0,<=   ?3' ' / /A KKf-- . . . .      L   k   !  A!122 "#"4%+=+=fa,,(( #2T["@"@d)''FF"6UFKK] >''FF&uF==\  E!     % 1  |   ,    %%e,,,r$)rTN)TFr'NF)%r]r^r_r`rardeprecated_paramsrnrbrcrrryrrrrvrrrrr+rMrrrrrrrrFrr r rr  __classcell__rs@r"rfrfsFFP NT 696969pT_  "!!X!   B B B B B R####JIIXI @ @X @4 4 4 l...      66X6 6 6X 6   ===<<X< , , ,///,333*T_  NNN!!! 7<         L L L L J J J J"  K-K-K-K-K-K-K-K-r$rfcneZdZdZdZfdZdZdZdZdZ dZ d Z d Z d Z d Z ddZddZxZS)r)z(Represents a column in a database table.rc |dd}|dd}t|}|rKt|dtjr+|t jd|d}|rC|d}t|dr+|t jd|d}|%t||dd}nd|vrt jd tt| |||d ||_ |d d |_ |d |j |_|dd|_|dd|_|dd|_|dd|_|dd|_|dd |_|dd|_|dd|_|dd|_t1|_t1|_|dd|_d|_d|vr|d|_n4t|jt>r|j ||jt|jtBtDfr|#|jntI|jdd rDt|jtj%r%tj&d|j d|jd|#tC|j|jot|jtNr.|#|j(d n'|#tS|j|jet|jtBtDfr|#|jn)|#tC|jd|jqt|jtNr.|#|j(dn)|#tS|jd|j*|tj+|d |vr|d |_,|j-d!i|dS)"aI 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:`_schema.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:`_schema.Column` is made to refer to another column using :class:`_schema.ForeignKey` and/or :class:`_schema.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:`_schema.Column` object. .. versionchanged:: 0.9.0 Support for propagation of type to a :class:`_schema.Column` from its :class:`_schema.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:`_schema.ForeignKey`, :class:`.ColumnDefault`, :class:`.Sequence`, :class:`.Computed`. In some cases an equivalent keyword argument is available such as ``server_default``, ``default`` and ``unique``. :param autoincrement: Set up "auto increment" semantics for an integer primary key column. The default value is the string ``"auto"`` which indicates that a single-column primary key that is of an INTEGER type with no stated client-side or python-side defaults should receive auto increment semantics automatically; all other varieties of primary key columns will not. This includes that :term:`DDL` such as PostgreSQL SERIAL or MySQL AUTO_INCREMENT will be emitted for this column during a table create, as well as that the column is assumed to generate new integer primary key values when an INSERT statement invokes which will be retrieved by the dialect. The flag may be set to ``True`` to indicate that a column which is part of a composite (e.g. multi-column) primary key should have autoincrement semantics, though note that only one column within a primary key may have this setting. It can also be set to ``True`` to indicate autoincrement semantics on a column that has a client-side or server-side default configured, however note that not all dialects can accommodate all styles of default as an "autoincrement". It can also be set to ``False`` on a single-column primary key that has a datatype of INTEGER in order to disable auto increment semantics for that column. .. versionchanged:: 1.1 The autoincrement flag now defaults to ``"auto"`` which indicates autoincrement semantics by default for single-column integer primary keys only; for composite (multi-column) primary keys, autoincrement is never implicitly enabled; as always, ``autoincrement=True`` will allow for at most one of those columns to be an "autoincrement" column. ``autoincrement=True`` may also be set on a :class:`_schema.Column` that has an explicit client-side or server-side default, subject to limitations of the backend database and dialect. The setting *only* has an effect for columns which are: * Integer derived (i.e. INT, SMALLINT, BIGINT). * Part of the primary key * Not referring to another column via :class:`_schema.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 a column that refers to another via foreign key, as such a column is required to refer to a value that originates from elsewhere. 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 using an "autoincrement" method specific to the backend database, such as calling upon ``cursor.lastrowid``, using RETURNING in an INSERT statement to get at a sequence-generated value, or using special functions such as "SELECT scope_identity()". These methods are highly specific to the DBAPIs and databases in use and vary greatly, so care should be taken when associating ``autoincrement=True`` with a custom default generation function. :param default: A scalar, Python callable, or :class:`_expression.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:`_schema.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 on the Python side. This attribute does **not** render SQL comments; use the :paramref:`_schema.Column.comment` parameter for this purpose. :param key: An optional string identifier which will identify this ``Column`` object on the :class:`_schema.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 a :class:`_schema.Index` construct will be automatically generated for this :class:`_schema.Column`, which will result in a "CREATE INDEX" statement being emitted for the :class:`_schema.Table` when the DDL create operation is invoked. Using this flag is equivalent to making use of the :class:`_schema.Index` construct explicitly at the level of the :class:`_schema.Table` construct itself:: Table( "some_table", metadata, Column("x", Integer), Index("ix_some_table_x", "x") ) To add the :paramref:`_schema.Index.unique` flag to the :class:`_schema.Index`, set both the :paramref:`_schema.Column.unique` and :paramref:`_schema.Column.index` flags to True simultaneously, which will have the effect of rendering the "CREATE UNIQUE INDEX" DDL instruction instead of "CREATE INDEX". The name of the index is generated using the :ref:`default naming convention ` which for the :class:`_schema.Index` construct is of the form ``ix__``. As this flag is intended only as a convenience for the common case of adding a single-column, default configured index to a table definition, explicit use of the :class:`_schema.Index` construct should be preferred for most use cases, including composite indexes that encompass more than one column, indexes with SQL expressions or ordering, backend-specific index configuration options, and indexes that use a specific name. .. note:: the :attr:`_schema.Column.index` attribute on :class:`_schema.Column` **does not indicate** if this column is indexed or not, only if this flag was explicitly set here. To view indexes on a column, view the :attr:`_schema.Table.indexes` collection or use :meth:`_reflection.Inspector.get_indexes`. .. seealso:: :ref:`schema_indexes` :ref:`constraint_naming_conventions` :paramref:`_schema.Column.unique` :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. :param nullable: When set to ``False``, will cause the "NOT NULL" phrase to be added when generating DDL for the column. When ``True``, will normally generate nothing (in SQL this defaults to "NULL"), except in some very specific backend-specific edge cases where "NULL" may render explicitly. Defaults to ``True`` unless :paramref:`_schema.Column.primary_key` is also ``True``, in which case it defaults to ``False``. 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 will 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``. .. seealso:: :ref:`metadata_defaults` - complete discussion of onupdate :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:`_schema.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` - complete discussion of server side defaults :param server_onupdate: A :class:`.FetchedValue` instance representing a database-side default generation function, such as a trigger. This indicates to SQLAlchemy that a newly generated value will be available after updates. This construct does not actually implement any kind of generation function within the database, which instead must be specified separately. .. warning:: This directive **does not** currently produce MySQL's "ON UPDATE CURRENT_TIMESTAMP()" clause. See :ref:`mysql_timestamp_onupdate` for background on how to produce this clause. .. seealso:: :ref:`triggered_columns` :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``, and the :paramref:`_schema.Column.index` parameter is left at its default value of ``False``, indicates that a :class:`_schema.UniqueConstraint` construct will be automatically generated for this :class:`_schema.Column`, which will result in a "UNIQUE CONSTRAINT" clause referring to this column being included in the ``CREATE TABLE`` statement emitted, when the DDL create operation for the :class:`_schema.Table` object is invoked. When this flag is ``True`` while the :paramref:`_schema.Column.index` parameter is simultaneously set to ``True``, the effect instead is that a :class:`_schema.Index` construct which includes the :paramref:`_schema.Index.unique` parameter set to ``True`` is generated. See the documentation for :paramref:`_schema.Column.index` for additional detail. Using this flag is equivalent to making use of the :class:`_schema.UniqueConstraint` construct explicitly at the level of the :class:`_schema.Table` construct itself:: Table( "some_table", metadata, Column("x", Integer), UniqueConstraint("x") ) The :paramref:`_schema.UniqueConstraint.name` parameter of the unique constraint object is left at its default value of ``None``; in the absence of a :ref:`naming convention ` for the enclosing :class:`_schema.MetaData`, the UNIQUE CONSTRAINT construct will be emitted as unnamed, which typically invokes a database-specific naming convention to take place. As this flag is intended only as a convenience for the common case of adding a single-column, default configured unique constraint to a table definition, explicit use of the :class:`_schema.UniqueConstraint` construct should be preferred for most use cases, including composite constraints that encompass more than one column, backend-specific index configuration options, and constraints that use a specific name. .. note:: the :attr:`_schema.Column.unique` attribute on :class:`_schema.Column` **does not indicate** if this column has a unique constraint or not, only if this flag was explicitly set here. To view indexes and unique constraints that may involve this column, view the :attr:`_schema.Table.indexes` and/or :attr:`_schema.Table.constraints` collections or use :meth:`_reflection.Inspector.get_indexes` and/or :meth:`_reflection.Inspector.get_unique_constraints` .. seealso:: :ref:`schema_unique_constraint` :ref:`constraint_naming_conventions` :paramref:`_schema.Column.index` :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`. :param comment: Optional string that will render an SQL comment on table creation. .. versionadded:: 1.2 Added the :paramref:`_schema.Column.comment` parameter to :class:`_schema.Column`. r Ntype_rz0May not pass name positionally and as a keyword. _sqla_typez1May not pass type_ positionally and as a keyword.rPz9Explicit 'name' is required when sending 'quote' argumentr+rFnullabledefaultserver_defaultserver_onupdaterrsystemdoconupdate autoincrementautor_proxies_warn_on_bytestringzUnicode column 'z ' has non-unicode default value z specified.T for_updaterHr).rrrr(r string_typesrr<hasattrrrr)rr+rr)r*r+r,rrr-r.r/r0rrrrcomputedr2typer r9 ColumnDefaultSequencerr binary_typer FetchedValue_as_for_update DefaultClauserBset_creation_orderrHr)r=r>rEr r'coltypers r"rzColumn.__init__Cs H zz&$'' 7D))Dzz  #$q'4#455 ##+Jxx{{  $1gGw -- $$+K   tVZZ%>%>??DD   #N  fd$$T5111::eT**!::mU;; :43C/CDD zz)T22 $jj)94@@%zz*;TBB ZZ.. jj400 jj511 ::eT** :t44 #ZZ@@55EEzz)T22     "JJz22DMM  #4 5 5 6 I / / 5 5 5 < #$,(ABB 9 DL))))49&;UCC!$,0@AA  $xxx7  M$,77888   *$-|<< @ D/>>uEEFFFF M$*=>>??? = $$--)BCC K DM**** M$-DIIIJJJ   +$. ==  D0??EEFFFF !$"64HHH $ %%% V   6**DI$$V$$$$$r$c 0||dSr'rrDs r"rzColumn._extra_kwargs)rr$c|jdS|j*|jjr|jjdz|jzS|jS|jS)Nz (no name)r)r r*named_with_columnrrLs r"rzColumn.__str__0sN 9 ; Z #z+ (z-3d6FFF''# #r$ch|jD])}|jj|jrdS*dS)zOReturn True if this Column references the given column via foreign key.TF)rr proxy_set intersectionr=rfks r" referenceszColumn.references;sG#  By"//0@AA tt 5r$c0||dSr'r)r=rIs r"append_foreign_keyzColumn.append_foreign_keyEs $$T*****r$cg}jjkr|djr|djs|djr|djr|djr|djr|ddd tjgtj gzd j Dzd j Dzjdurd jjzpd gzfd|DzzS)Nr+rr)r/r*r+rz Column(%s)rc0g|]}|t|Sr'rrs r"rz#Column.__repr__..[sCCC1Q]tAww]]]r$c,g|]}t|Srrrs r"rz#Column.__repr__..\s1111tAww111r$z table=<%s>z table=Nonec Tg|]$}|dtt|%Srrrs r"rz#Column.__repr__..ds7DDD!!!T'$"2"23334DDDr$)r+r rrr)r/r*r+rrrr9rrr*r)r=kwargs` r"rMzColumn.__repr__Hs 8ty LL      ( LL ' ' '} % LL $ $ $ = % LL $ $ $ < $ LL # # #   + LL) * * * < $ LL # # #dii $)__ DI CC 1CCC D21 0111 2 Jd*>$tz'==$#  EDDDeDDD E    r$c |jstjd|j |j|_t |dd}|)|ur%tjd|jd|jd|jjvrtj|j}||urQ|jD]I}j ||j j vrj |j Jj ||_ |jrj|n3|jjvr%tjd|jdjd|jrqt%|jt&jrtjdt-d|jt/|jd nc|jr\t%|jt&jrtjd t3|jd |fd dS)NzfColumn must be constructed with a non-blank name or assign a non-blank .name before adding to a Table.r*zColumn object 'z' already assigned to Table ''z'Trying to redefine primary-key column 'z(' as a non-primary-key column on table 'zThe 'index' keyword argument on Column is boolean only. To create indexes with a specific name, create an explicit Index object external to the Table.T)rrzThe '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.)rc.|Sr')_set_remote_table)rIr*s r"rz$Column._set_parent..sr/C/CE/J/Jr$)r rr<r+rrrrYrrrrr0r*r_replacerrr(rr6rrrtrUniqueConstraint_setup_on_memoized_fks)r=r*existingr-rIs ` r"rzColumn._set_parentgsy #E  8 yDH4$//  HE$9$9##888X1113  8u~ % %.$$TX..C$*@@B&--b111}(999)00??? t$$$      & &t , , , , X* * *##888U^^^-  : $*d&788 'C  # #$(4 +<+<4     [ $+t'899 ':  # # ===    ##$J$J$J$JKKKKKr$c|jj|jfdf|jj|jfdfg}|D]F\}}||jjjvr.|jjj|D]}|j|ur ||GdS)NFT)r*r+r r _fk_memos link_to_name)r=rfk_keysfk_keyr\rIs r"rXzColumn._setup_on_memoized_fkssjndh ' /jndi ($ / %,   FL,666*-7?B,662   r$cf|j|||jdStj|d|dS)Nrz)r*rr)r=rs r"_on_table_attachzColumn._on_table_attachs? : ! BtTZ L4b 9 9 9 9 9r$c fd|jDfd|jDz}i}|jD]9}|j|j}|D]\}}|||dz|z<:|j}|j} t|tr)dx}} | |jj di|j } t| tr | j di} |j ||j| |j|j|j|j|j|j|j|j||j| |j|jd|} || S)zuCreate a copy of this ``Column``, uninitialized. This is used in :meth:`_schema.Table.tometadata`. c8g|]}|j |jdiSr)rrTrr,r~s r"rzColumn.copy..s>   !- AFLLRLL   r$c8g|]}|j |jdiSrc)rrTrds r"rzColumn.copy..s. I I IaAL IVQV\\b\\ I I Ir$rN)r r'r+rr)rr-rr0r*r+r/r,r.rr)rrdialect_options _non_defaultsitemsr+r,r(ComputedrrTr9r _constructorr r+rr)rr-rr0r*r/r.rrW) r=r~r> column_kwargs dialect_namerfdialect_option_keydialect_option_valuer+r,r'r,s ` r"rTz Column.copys    "&"2   I I I I4#4 I I IJ   0 ) )L"2<@NO!&&(( ) )"$) 3&);;  ),. nh / / 8/3 3N_ KK0+066266 7 7 7  e. / / %EJ$$$$E D "!(];;*,L)]+L!  $%  (%%a(((r$NFc d|jD}||jtjd |j|rt |p|jn|p|j|jg|R|r|n |r|n|j|j|j |gd}nB#t$r5}tj td|j z|Yd}~nd}~wwxYw||_|j||j)|jj|j|_|jr|j||j|||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. cDg|]}t|j|jS)) _constraint) ForeignKeyrr)rfs r"rz&Column._make_proxy..s9    qxQ\ : : :   r$Nz^Cannot initialize a sub-selectable with this Column object until its 'name' has been assigned.)r+rr)r2zCould 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.from_)rr rrurjr r9r+rr)rprr;rr*rr _is_clone_ofrrYrUrz) r= selectabler r+name_is_truncatabler~rIr,rAs r" _make_proxyzColumn._make_proxys  &    CCD$>DDdh ,   AA    K:=AN K          """  " .'4<@@GGAN   *  " & &q ) ) ) &&q*555sAB C +B<<Cc |rBd|j|jfDt|jzt|jzSt j|fi|S)Ncg|]}||Sr'rrs r"rz'Column.get_children..-sKKKqQ]]]]r$)r*r/rrrrrF)r=rrEs r"rFzColumn.get_children*sj  =KKT\4=9KKKt())*t'(()   ,T<s22Nd%d%d%d%d%L... $ $ $+++   >BLBLBLH   ::: 6)6)6)rDI4444l========r$r)ceZdZdZdZ ddZdZddZddZe d Z d Z e eZ d Z d Zejd ZdZdZdZejdZdZdZdZdZdS)rra;Defines a dependency between two columns. ``ForeignKey`` is specified as an argument to a :class:`_schema.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:`_schema.ForeignKeyConstraint` object. This object will be generated automatically when a ``ForeignKey`` is associated with a :class:`_schema.Column` which in turn is associated with a :class:`_schema.Table`. Conversely, when :class:`_schema.ForeignKeyConstraint` is applied to a :class:`_schema.Table`, ``ForeignKey`` markers are automatically generated to be present on each associated :class:`_schema.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:`_schema.ForeignKeyConstraint` object must be used, and applied to the :class:`_schema.Table`. The associated ``ForeignKey`` objects are created automatically. The ``ForeignKey`` objects associated with an individual :class:`_schema.Column` object are available in the `foreign_keys` collection of that column. Further examples of foreign key configuration are in :ref:`metadata_foreignkeys`. foreign_keyNFc  ||_t|jtjrd|_nt |jdr|j|_n |j|_t|jtstj d|jzt|jj tj tfs!tj d|jj z||_ d|_||_||_||_||_||_||_| |_| |_| r| |_| |_dS)a Construct a column-level FOREIGN KEY. The :class:`_schema.ForeignKey` object when constructed generates a :class:`_schema.ForeignKeyConstraint` which is associated with the parent :class:`_schema.Table` object's collection of constraints. :param column: A single target column for the key relationship. A :class:`_schema.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. :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 when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param ondelete: Optional string. If set, emit ON DELETE 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 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:`_schema.ForeignKeyConstraint` to indicate the constraint should be generated/dropped externally from the CREATE TABLE/ DROP TABLE statement. See :paramref:`_schema.ForeignKeyConstraint.use_alter` for further description. .. seealso:: :paramref:`_schema.ForeignKeyConstraint.use_alter` :ref:`use_alter` :param match: Optional string. If set, emit MATCH 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 ``_``. The arguments are ultimately handled by a corresponding :class:`_schema.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)_colspecr(rr6 _table_columnr7rrrr<r*NoneTyperrparent use_alterr r/ondelete deferrable initiallyr\matchrH_unvalidated_dialect_kw) r=rrqrr r/rrrr\rrH dialect_kws r"rzForeignKey.__init___sWj dmT%6 7 7 !%D  t}&:;; 3%)]%E%E%G%G""%)]"d0,?? '')-);< "(4=+*F '*,0,>,DE& "     $"(  DI'1$$$r$c0d|zS)NzForeignKey(%r)) _get_colspecrLs r"rMzForeignKey.__repr__s$"3"3"5"555r$c t||f|j|j|j|j|j|j|j|j d|j }| |S)aProduce a copy of this :class:`_schema.ForeignKey` object. The new :class:`_schema.ForeignKey` will not be bound to any :class:`_schema.Column`. This method is usually used by the internal copy procedures of :class:`_schema.Column`, :class:`_schema.Table`, and :class:`_schema.MetaData`. :param schema: The returned :class:`_schema.ForeignKey` will reference the original table and column name, qualified by the given string schema name. r)rr r/rrrr\r) rrrrr r/rrrr\rrrW)r=r!rIs r"rTzForeignKey.copys}    V  , ,  n]]n**   *   %%b)))r$c|r|j\}}}||}|d|d|S|r|j\}}}|r |d|d|S|d|S|j |jjjd|jjS|jS)zReturn a string based 'column specification' for this :class:`_schema.ForeignKey`. This is usually the equivalent of the string-based "tablename.colname" argument first passed to the object's constructor. Nr)_column_tokensrr*rr+r)r=r! table_name_schematnamecolnames r"rzForeignKey._get_colspecs  !&*&9 #GUG%"!'8 8  !%)%8 "FE7 7%+VVZZZAA",**gg66   +"(111"&&  = r$c|jdS)Nr)rrLs r"rzForeignKey._referred_schemas"1%%r$c|j|jjdS|jjjS|j\}}}t ||Sr')rr*r+rr#)r=r!rrs r" _table_keyzForeignKey._table_keysJ   )!'/t)/33%)%8 "FE7!%00 0r$c:||jduS)zrReturn True if the given :class:`_schema.Table` is referenced by this :class:`_schema.ForeignKey`.Ncorresponding_columnrrs r"rJzForeignKey.references)s ))$+66dBBr$c6||jS)aReturn the :class:`_schema.Column` in the given :class:`_schema.Table` referenced by this :class:`_schema.ForeignKey`. Returns None if this :class:`_schema.ForeignKey` does not reference the given :class:`_schema.Table`. rrs r" get_referentzForeignKey.get_referent0s))$+666r$c|d}|tjd|jzt |dkr|}d}n(|}|}t |dkrd|}nd}|||fS)z7parse a string-based _colspec into its component parts.rNz,Invalid foreign key column specification: %srr)rsplitrr<rlenrrr)r=mrrr!s r"rzForeignKey._column_tokens=s      % %c * * 9#>N  q66Q;;EEGGEGGeeggGEEGGE q66A::XXa[[FFFug%%r$cj|jtjd|jjtjd|jj}|jjD]$}t |t r |j|usJn%J|j\}}}||jj |jj }t||}|||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.) rrrur* base_columnsr(r)rrr!r#)r= parenttabler,r!rrtablekeys r"_resolve_col_tokenszForeignKey._resolve_col_tokens\s ; )4  [  &)   k' )  A!V$$ w+----  5"&!4w >k29E )0F!%00Hg--r$c t|jds ||j_n|jj|usJd}|-|j}|j|jjd}n>|jr|}|jD]}|j|kr|}n|}|j|d}|7tj d|j d|jd|jd|d |j|| |dS)N_referred_table3Could not initialize target column for ForeignKey ' ' on table ' ': table '' has no column named 'rS) r7rrrr,rYr+r\r rNoReferencedColumnErrorr_set_target_column)r=rr*r_columnr+r,s r"_link_to_col_by_colstringz$ForeignKey._link_to_col_by_colstrings*t(9:: <.3DO + +?2e;;;; ? +Cgkk$+/488GG   1CW  6W$$G Cgkk'400G ?--===+"2"2"2EJJJE    (((((r$c|jjjrj|j_t|jjt rfd}|j||_dS)NcP|jjjrj|j_dSdSr')rr9_isnull)rIrs r"set_typez/ForeignKey._set_target_column..set_types+9>)1%+[BINNN11r$)rr9rr(r*rfrXr)r=rrs ` r"rzForeignKey._set_target_columnst ;  # +%{DK  dk' / / 9 1 1 1 1 1 K . .x 8 8 8 r$c t|jtjr|\}}}||jvr$t jd|jd|d|d||j |jvrt j d|zt j d|jd|j d|d |d ||t|jd r|j}|S|j}|S) aReturn the target :class:`_schema.Column` referenced by this :class:`_schema.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 'z' could not find table 'z9' with which to generate a foreign key to target column 'rSz9Table %s is no longer associated with its parent MetaDatarrrrr)r(rrr6rrrNoReferencedTableErrorrr+rurr r7r)r=rrrrs r"rzForeignKey.columns3 dmT%6 7 7 -1-E-E-G-G *K7{33300{{{HHHggg7  (<<<-&(34 11}}}k&6&6&6'''K T]$8 9 9 m6688GNmGNr$c|j|j|urtjd||_|jj||j|jdS)Nz&This ForeignKey already has a parent !)rrrurrr` _set_tablers r"rzForeignKey._set_parentsn ; "t{&'@'@)8    $$T*** $$T_55555r$c|\}}}|||||j|dSr')rrr_validate_dest_table)r=r*rrrs r"rUzForeignKey._set_remote_tablesN)-)A)A)C)C& Xw &&{E7CCC ,,U33333r$c|\}}}||f}||j|vr"|j||dSdSr')rr[r)r=rr table_keyrr^s r"_remove_from_metadataz ForeignKey._remove_from_metadatasa*.*B*B*D*D' YW% 8%f- - -  v & - -d 3 3 3 3 3 . -r$c |jt|trxtggf|j|j|j|j|j|j |j d|j |_|j |||j ||j|t|jt"jr|\}}}||f}||jjvr@|jj|} ||||n#t.j$rYnwxYw|jj||dSt7|jdr0|j}||dS|j}||dS)N)rr r/rrrrr)rr(rfrrr r/rrrrr_append_elementr9rrrrr6rrrsrrrr[rr7rr)r=rr*rrrr^rs r"rzForeignKey._set_tables ? "z%'?'? "2 .Y?.j  .  DO O + +FD 9 9 9 O 5 5e < < < t$$$ dmT%6 7 7 -.2.F.F.H.H +KG)FK0777#,3I>22;wOOOO2D  *6 2 9 9$ ? ? ? ? ? T]$8 9 9 -m6688G  # #G , , , , ,mG  # #G , , , , ,s D##D54D5) NFNNNNNFNNr'NN)r]r^r_r`rarrMrTrrbrrtarget_fullnamerJrrrdrrrrrrrUrrrr$r"rrrr5s%%N#N   |2|2|2|2|666****<!!!!6&&X&111h|,,OCCC 7 7 7 &&&) s43J3J3L3Lr$c*|Sr'rrLs r"rz_NotAColumnExpr.* s$*A*A*C*Cr$N)r]r^r_rr self_grouprb _from_objectsrr$r"rr" sA   'M&LLHCCDDMMMr$rcTeZdZdZdZdZdZdZd dZdZ d dZ dZ e d Z dS) DefaultGeneratorz'Base class for column *default* values.default_generatorFNc||_dSr'r4r=r5s r"rzDefaultGenerator.__init__6 $r$cV||_|jr||j_dS||j_dSr')rr5r/r*rs r"rzDefaultGenerator._set_parent9 s3 ? '#'DK "&DK   r$c @|t|}|j|fi|Sr')rexecute)r=rrEs r"rzDefaultGenerator.execute@ s. <!$''Dt|D++F+++r$c0||||Sr')_execute_default)r=r multiparamsparamss r"_execute_on_connectionz'DefaultGenerator._execute_on_connectionE s**4fEEEr$cJt|dd|jjjSdS)z4Return the connectable associated with this default.rN)rrr*rrLs r"rzDefaultGenerator.bindH s) 44 ( ( 4;$) )4r$r|r')r]r^r_r`ra is_sequenceis_server_defaultrrrrrrbrrr$r"rr- s11(NK F%%%%''',,,, FFFXr$rceZdZdZfdZejdZejdZejdZ ejej ddZ dZ d Z ee Zd ZxZS) r:aA 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:`_schema.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 tt|jdi|t|trt jdtj|r| |}||_ dS)a{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:`_expression.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:`_engine.Connection` in use as well as the current statement and parameters. z4ColumnDefault may not be a server-side default type.Nr) rr:rr(r=rr<rcallable_maybe_wrap_callablearg)r=rrErs r"rzColumnDefault.__init__g s4 ,mT""+55f555 c< ( ( #F  =   1++C00Cr$c4tj|jSr')rrrrLs r" is_callablezColumnDefault.is_callable s}TX&&&r$c6t|jtSr')r(rrrLs r"is_clause_elementzColumnDefault.is_clause_element s$(M222r$c2|j o|j o|j Sr')rrrrLs r" is_scalarzColumnDefault.is_scalar s.  %** %$$ r$zsqlalchemy.sql.sqltypescT|jr t|jj|j SdSr!)rr(rr9NullType)r=sqltypess r" _arg_is_typedzColumnDefault._arg_is_typed s.  ! !$(-1BCCC C5r$cj tjd}n(#t$rtjfdcYSwxYw|ddurt |dpd}t |d|z }|dkrtjfdS|dkrSt jd ) zWrap 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. T)no_selfcSr'rctxrs r"rz4ColumnDefault._maybe_wrap_callable.. ""$$r$NrcSr'rrs r"rz4ColumnDefault._maybe_wrap_callable.. rr$rzDColumnDefault Python function takes zero or one positional arguments)rget_callable_argspecrp wrap_callablerrr<)r=rargspec defaulted positionalss ` r"rz"ColumnDefault._maybe_wrap_callable s </DAAAGG < < <%&6&6&6&6;; ; ; ; <AJd*>s71:C! '!*oo 1 !  %&6&6&6&6;; ; A  I#' s "??c|jrdSdS)Ncolumn_onupdatecolumn_defaultr4rLs r" _visit_namezColumnDefault._visit_name s ? $$$##r$cd|jdS)NzColumnDefault())rrLs r"rMzColumnDefault.__repr__ s&*hhh00r$)r]r^r_r`rrrdrrr dependenciesrrrrbrarMr#r$s@r"r:r:Q s*!!!!!F ''' 333     T01121 4$$$ Xk**N1111111r$r:c,eZdZdZ ddZdS)IdentityOptionszDefines options for a named database sequence or an identity column. .. versionadded:: 1.3.18 .. seealso:: :class:`.Sequence` Nc ||_||_||_||_||_||_||_||_| |_dS)aiConstruct a :class:`.IdentityOptions` object. See the :class:`.Sequence` documentation for a complete description of the parameters :param start: the starting index of the sequence. :param increment: the increment value of the sequence. :param minvalue: the minimum value of the sequence. :param maxvalue: the maximum value of the sequence. :param nominvalue: no minimum value of the sequence. :param nomaxvalue: no maximum value of the sequence. :param cycle: allows the sequence to wrap around when the maxvalue or minvalue has been reached. :param cache: optional integer value; number of future values in the sequence which are calculated in advance. :param order: optional boolean value; if ``True``, renders the ORDER keyword. name. N start incrementminvaluemaxvalue nominvalue nomaxvaluecyclecacheorder) r=rrrrrrr r r s r"rzIdentityOptions.__init__ sG> "    $$   r$) NNNNNNNNNr]r^r_r`rrr$r"rr sO''''''r$rceZdZdZdZdZ ddZejdZ ejdZ ej d d Z fd Z d Zd ZedZddZddZdZxZS)r;aRepresents 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.Engine` or :class:`_engine.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:`_schema.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` sequenceTNFc t||t||||||||| |  t|| |_| |_| t ur dx|_} n/|| |jr|jx|_} nt| ||_||_t|| |_ |r| |dSdS)alConstruct 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:`_schema.MetaData` is also present are the same as that of :paramref:`_schema.Table.schema`. :param cache: optional integer value; number of future values in the sequence which are calculated in advance. Renders the CACHE keyword understood by Oracle and PostgreSQL. .. versionadded:: 1.1.12 :param order: optional boolean value; if ``True``, renders the ORDER keyword, understood by Oracle, indicating the sequence is definitively ordered. May be necessary to provide deterministic ordering using Oracle RAC. .. versionadded:: 1.1.12 :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 :paramref:`_schema.Sequence.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:`_schema.MetaData` object which this :class:`.Sequence` will be associated with. A :class:`.Sequence` that is associated with a :class:`_schema.MetaData` gains the following capabilities: * The :class:`.Sequence` will inherit the :paramref:`_schema.MetaData.schema` parameter specified to the target :class:`_schema.MetaData`, which affects the production of CREATE / DROP DDL, if any. * The :meth:`.Sequence.create` and :meth:`.Sequence.drop` methods automatically use the engine bound to the :class:`_schema.MetaData` object, if any. * The :meth:`_schema.MetaData.create_all` and :meth:`_schema.MetaData.drop_all` methods will emit CREATE / DROP for this :class:`.Sequence`, even if the :class:`.Sequence` is not associated with any :class:`_schema.Table` / :class:`_schema.Column` that's a member of this :class:`_schema.MetaData`. The above behaviors can only occur if the :class:`.Sequence` is explicitly associated with the :class:`_schema.MetaData` via this parameter. .. seealso:: :ref:`sequence_metadata` - full discussion of the :paramref:`.Sequence.metadata` parameter. :param for_update: Indicates this :class:`.Sequence`, when associated with a :class:`_schema.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. r4rN) rrrrr optionalrqr!rr#_key _set_metadata)r=r rrrrrrr r!r r rrPrrr5s r"rzSequence.__init__ sl !!$:!>>>  !! !  e,,   \ ! !#' 'DK&&  !fnn#+? 2DK&&%fl;;DK  "400  )   x ( ( ( ( ( ) )r$cdSr!rrLs r"rzSequence.is_callable ur$cdSr!rrLs r"rzSequence.is_clause_element rr$zsqlalchemy.sql.functions.funcc:|||jS)zReturn a :class:`.next_value` function element which will render the appropriate increment function for this :class:`.Sequence` within any SQL expression. r) next_valuer)r=funcs r"rzSequence.next_value st$)444r$ctt||||jdSr')rr;rr`r)r=rrs r"rzSequence._set_parent s= h))&11100000r$c:||jdSr')rr)r=rr*s r"rzSequence._set_table s 5>*****r$c<||_||jj|j<dSr')r _sequencesrrs r"rzSequence._set_metadata s   .2  +++r$c,|jr |jjSdSr'rrLs r"rz Sequence.bind s = =% %4r$cl|t|}|tj||dS)z&Creates this sequence in the database.Nrrrs r"r zSequence.create s: <!$''D #-t KKKKKr$cl|t|}|tj||dS)z&Drops this sequence from the database.Nrr rs r"r z Sequence.drop s: <!$''D #+TjIIIIIr$cDtjd|jjz)NzThis %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.rrLs r"rzSequence._not_a_column_expr s+% #&*^%< =   r$)NNNNNNNNNNFNNNF)NT)r]r^r_r`rarrrrdrrrrrrrrbrr r rr#r$s@r"r;r; sv< NK #n)n)n)n)`  T6775587511111+++333X LLLLJJJJ       r$r;c>eZdZdZdZdZdZd dZdZdZ dZ dZ d S) r=aA 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` TFc||_dSr'r4rs r"rzFetchedValue.__init__# rr$cF||jkr|S||Sr')r5_cloners r"r>zFetchedValue._as_for_update& s&  ( (K;;z** *r$c|j|j}|j|j|jdd||_|S)Nr)rrnrSupdaterrr5)r=r5ns r"r%zFetchedValue._clone, sS N " "4> 2 2 $-((( x&&&! r$cV||_|jr||j_dS||j_dSr')rr5r,r+rs r"rzFetchedValue._set_parent3 s3 ? .*.DK ' ' ')-DK & & &r$c*tj|Sr'rJrLs r"rMzFetchedValue.__repr__: s &&&r$Nr|) r]r^r_r`r reflected has_argumentrr>r%rrMrr$r"r=r= s&IL%%%%+++ ...'''''r$r=c.eZdZdZdZdfd ZdZxZS)r?a>A 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:`_schema.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")) TFctj|tjdttfdt t ||||_||_ dS)Nrr) rassert_arg_typer6rrrr?rrr+)r=rr5 _reflectedrs r"rzDefaultClause.__init__V s`  $#A& zBE    mT""++J777#r$c(d|jd|jdS)NzDefaultClause(z , for_update=r)rr5rLs r"rMzDefaultClause.__repr__^ s59XXXtOOr$)FF)r]r^r_r`r,rrMr#r$s@r"r?r?> sd*L$$$$$$PPPPPPPr$r?z0.6zy:class:`.PassiveDefault` is deprecated and will be removed in a future release. Please refer to :class:`.DefaultClause`.ceZdZdZdZdS)PassiveDefaultz%A DDL-specified DEFAULT column value.c0tj|g|Ri|dSr')r?r)r=rr~s r"rzPassiveDefault.__init__j s)t0c000R00000r$Nr rr$r"r3r3b s+ 0/11111r$r3cLeZdZdZdZ d dZedZdZdZ dS) ConstraintzA table-level SQL constraint.rNFc ||_||_||_|r||_||_||_t j|||dS)aCreate 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 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 ``_``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. N) r rrrH _create_rulerrr@r)r=r rrr8rHrrs r"rzConstraint.__init__s sdh $"  DI(& %%% %%j11111r$c t|jtr|jSn#t$rYnwxYwt jd)NzdThis constraint is not bound to a table. Did you mean to call table.append_constraint(constraint) ?)r(rrfr:rrurLs r"r*zConstraint.table sc $+u-- #{" #    D % A   s $ 11cH||_|j|dSr')rrrr=rs r"rzConstraint._set_parent s& t$$$$$r$c tr')NotImplementedError)r=r~s r"rTzConstraint.copy s!###r$)NNNNNF) r]r^r_r`rarrbr*rrTrr$r"r6r6n s''!N <2<2<2<2|   X  %%%$$$$$r$r6ct|dr|}t|tst jd|S)Nrzschema.Column object expected)r7rr(r)rr<)elements r"_to_schema_columnr@ sPw,--/,,.. gv & &A ?@@@ Nr$c||St|dr|}t|tjt fzsd}t j||z|S)Nrz1Element %r is not a string name or column element)r7rr(rr6rrr<)r?rs r"_to_schema_column_or_stringrB sl . / //,,.. gt0M3CC D D/Ag ... Nr$cHeZdZdZ dZdZedZddZdZ dZ dS) ColumnCollectionMixinNFc|dd}|dd|_t|_d|D|_|r|jr|dSdSdS)N _autoattachTrFc,g|]}t|Sr)rBrs r"rz2ColumnCollectionMixin.__init__.. s.! ! ! /0 ' * *! ! ! r$)rrrr r_pending_colargs _check_attach)r=rr~rFs r"rzColumnCollectionMixin.__init__ sff]D11 FF>599')) ! ! 4;! ! !   !40 !     ! ! ! !r$c#K|D]}d}d}t|dr|}t|ttfs|}n)g}t j|id|ji|r|d}||n|}||||fVdS)Nrrr)r7rr(rrrtraverser)r}rrstrnamercols add_elements r""_extract_col_expression_collectionz8ColumnCollectionMixin._extract_col_expression_collection s 5 5DGFt122 1..00d]J$?@@ %!$Xt{,CDDD%!!WF$*$6&&GK4 4 4 4 4 5 5r$c djD}d|D}t|| rh|r JdtdjD|}|s) fd} _ D]}||dS|}d|D}t |dkr)|dSt |dkrijsd|dj fd |ddD} | rAtj d d d | Dd j ddSdSdS)Nc<g|]}t|t|Sr)r(r)rs r"rz7ColumnCollectionMixin._check_attach.. s'NNN! 1f8M8MNANNNr$cFg|]}t|jt|Sr)r(r*rfrs r"rz7ColumnCollectionMixin._check_attach.. s)JJJaz!'5/I/IJJJJr$z#Should not reach here on event callc3K|]}||V dSr'rrs r"rz6ColumnCollectionMixin._check_attach.. s+""AMMMMM""r$ct|tr/|sddSdSdS)NT)r)r(rfdiscardrI)rr* cols_wo_tabler=s r" _col_attachedz:ColumnCollectionMixin._check_attach.._col_attached sd"%//9%--f555,9 ..4.888889999r$ch|] }|j Srr*rs r" z6ColumnCollectionMixin._check_attach..$ s+++a!'+++r$rrc&g|] }|ju |SrrY)rr,r*s r"rz7ColumnCollectionMixin._check_attach..) s%EEEAu0D0Da0D0D0Dr$z Column(s) rc3 K|] }d|zV dSz'%s'Nrrs r"rz6ColumnCollectionMixin._check_attach... s&!=!=&1*!=!=!=!=!=!=r$z are not part of table ''.)rHr difference_cols_wo_tabler`rr9rr_allow_multiple_tablesr*rr<rr) r=rcol_objs cols_w_tablehas_string_colsrWr-rrsothersrVr*s ` @@r"rIz#ColumnCollectionMixin._check_attach sNNt4NNNJJ8JJJ H 00>>   A AA A A7"""0"""j"" # 999999'4#(88C((7777++7+++ v;;!    * *6::<< 8 8 8 8 8 [[1__T%@_AJ$EEEEEEEEF '' !=!=f!=!=!=====))) ___  r$c*fd|jDS)Ncbg|]+}t|tjr j|n|,Sr)r(rr6r,)rr-r*s r"rz:ColumnCollectionMixin._col_expressions..4 sE   'sD,=>> GEGCLLC   r$)rHrs `r"_col_expressionsz&ColumnCollectionMixin._col_expressions3 s1    ,    r$cn||D]}||j|dSr')rhrr)r=r*r-s r"rz!ColumnCollectionMixin._set_parent9 sE((// & &C   %%% & &r$r|) r]r^r_rrar classmethodrOrIrhrrr$r"rDrD sG#!!!55[5$////b   &&&&&r$rDcDeZdZdZdZdZ dZdZd dZdZ dZ d Z dS) ColumnCollectionConstraintz-A constraint that proxies a ColumnCollection.c|dd}|dd}tj|fi|tj|g|R||ddS)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 when issuing DDL for this constraint. :param \**kw: other keyword arguments including dialect-specific arguments are propagated to the :class:`.Constraint` superclass. rFTrF)rFrN)rrr6rrD)r=rr~rFrs r"rz#ColumnCollectionConstraint.__init__B s(ff]D11 vvne44 D''B'''&    (3,      r$Ncrt||t||dSr')r6rrDrs r"rz&ColumnCollectionConstraint._set_parentc s4tU+++))$66666r$c||jvSr')r)r=rs r" __contains__z'ColumnCollectionConstraint.__contains__g sDL  r$c i}jD]9}j|j}|D]\}}|||dz|z<:jfdjDjjjd|}|S)Nrc<g|]}t|jSr)r3r)rrr=r/s r"rz3ColumnCollectionConstraint.copy..{ s7!t{LAAr$)r rr) rfrgrhrrr rrrW) r=r/r~constraint_kwargsrlrfrmrnr,s `` r"rTzColumnCollectionConstraint.copyj s 0 ) )L"2<@NO!&&(( ) )"$)" 3&);;  ) DN Ln   %%a(((r$c6|j|S)zReturn True if this constraint contains the given column. Note that this object also contains an attribute ``.columns`` which is a :class:`_expression.ColumnCollection` of :class:`_schema.Column` objects. )rcontains_columnr=r-s r"ruz*ColumnCollectionConstraint.contains_column s|++C000r$cB|jjfdjDS)Nc3(K|] }|V dSr'r)rr+ ordered_dicts r"rz6ColumnCollectionConstraint.__iter__.. s(@@c S!@@@@@@r$)r_data_list)r=rys @r"__iter__z#ColumnCollectionConstraint.__iter__ s,|) @@@@\-?@@@@r$c4t|jjSr')rrrzrLs r"__len__z"ColumnCollectionConstraint.__len__ s4<%&&&r$r') r]r^r_r`rrrrprTrur|r~rr$r"rlrl? s77   6G 777!!!))))2 1 1 1AAA'''''r$rlceZdZdZdZeddd d fd Zd ZeeZd d Z xZ S) CheckConstraintzlA table- or column-level CHECK constraint. Can be included in the definition of a Table or Column. Tsqltextz:class:`.CheckConstraint`z$:paramref:`.CheckConstraint.sqltext`NFc t|d|_g} tj|jid| jit t |j| |||||| |d| |||dSdS)aConstruct 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 :func:`_expression.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 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 Tallow_coercion_to_textr)r rrr8rHrrFN) rrrrKrrrrr9) r=rr rrr*rHr8rFrr~rrs r"rzCheckConstraint.__init__ s^(MMM $,Xw~,FGGG-ot$$-!%##      * *5 1 1 1 1 1  r$c>t|jtrdSdS)Ncheck_constraintcolumn_check_constraint)r(rrfrLs r"razCheckConstraint.__visit_name__ s" dk5 ) ) -%%,,r$c |t|j|j|}n|j}t||j|j|j|j|d|j}| |S)NF)r rrr8r*rFr) r3rr*rr rrr8rrW)r=r/r~rr,s r"rTzCheckConstraint.copy sv  #'t|TZNNGGlG  n*( %%a(((r$)NNNNNNTFr') r]r^r_r`rar rrarbrTr#r$s@r"rr s "#. ;2;2;2;2;2  ;2z--- Xn--N))))))))r$rceZdZdZdZ ddZdZdZ dZ e dZ e dZ e d Z d Z e d Ze d Zd ZddZdS)raA 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:`_schema.ForeignKey` to the definition of a :class:`_schema.Column` is a shorthand equivalent for an unnamed, single column :class:`_schema.ForeignKeyConstraint`. Examples of foreign key configuration are in :ref:`metadata_foreignkeys`. foreign_key_constraintNFc  2tjf|||| d| |_|_| _|_| _tt|t|krUtt|t|krtj dtj dfd|D_ tjg|R| 2tdr | jusJ| dSdS)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 when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param ondelete: Optional string. If set, emit ON DELETE 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 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:`_schema.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:`_schema.MetaData.create_all` and :meth:`_schema.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:`_schema.ForeignKeyConstraint.use_alter` in typical use cases. .. seealso:: :ref:`use_alter` :param match: Optional string. If set, emit MATCH 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 ``_``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. .. versionadded:: 0.9.2 )r rrrHzOForeignKeyConstraint with duplicate source column references are not supported.z_ForeignKeyConstraint number of constrained columns must match the number of referenced columns.cg|]F}t|fjjjjjjjjd j GS)) rqr r/rrr\rrr) rrr r/rrr\rrrdialect_kwargs)rrefcolr=s r"rz1ForeignKeyConstraint.__init__.. s{      Y.!.j?.  %     r$Nr)r6rr/rr\rrrrrr<elementsrDr7rr9)r=r refcolumnsr r/rrrrr\rr*rHrs` r"rzForeignKeyConstraint.__init__ sln   !       !   (" s7||  J / /3w<<  CLL00'4'*    %    " &t6g6666  tX&& , ++++  * *5 1 1 1 1 1  r$cn|j||j|dSr')rrrrrHs r"rz$ForeignKeyConstraint._append_element s4     R     r$cZtjt|j|jSr')r OrderedDictzip column_keysrrLs r" _elementszForeignKeyConstraint._elements s$D$4dm D DEEEr$c*|jD] }|jcSdSr')rr)r=elems r"rz%ForeignKeyConstraint._referred_schema s'M  D( ( ( (4r$c0|jdjjS)alThe :class:`_schema.Table` object to which this :class:`_schema.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)rrr*rLs r"referred_tablez#ForeignKeyConstraint.referred_table s}Q&,,r$c td|jD}d|vrWt|dkrFt|dd\}}t jd|jd|jd|d|dSdS) Nc6g|]}|Sr)r)rrs r"rz=ForeignKeyConstraint._validate_dest_table.. s"FFF$//++FFFr$rrrzForeignKeyConstraint on (z$) refers to multiple remote tables:  and )rrrrrr<r_col_description)r=r* table_keyselem0elem1s r"rz)ForeignKeyConstraint._validate_dest_table sFF FFFGG z ! !c*oo&9&9!*--ac2LE5##>>>4#8#8#8%%%H  " !&9&9r$cvt|dr|jSd|jDS)aReturn a list of string keys representing the local columns in this :class:`_schema.ForeignKeyConstraint`. This list is either the original string arguments sent to the constructor of the :class:`_schema.ForeignKeyConstraint`, or if the constraint has been initialized with :class:`_schema.Column` objects, is the string ``.key`` of each element. .. versionadded:: 1.0.0 rcdg|]-}t|tr|jnt|.Sr)r(rr+str)rr-s r"rz4ForeignKeyConstraint.column_keys.. sC&c=99Gs3xxr$)r7rkeysrHrLs r"rz ForeignKeyConstraint.column_keys sN 4 " " <$$&& &0 r$c6d|jS)Nr)rrrLs r"rz%ForeignKeyConstraint._col_description syy)***r$c t|| t||nV#t$rI}t jt jd|jd|j dd|Yd}~nd}~wwxYwt|j |j D]3\}}t|dr |j|ur||4||dS)Nz,Can't create ForeignKeyConstraint on table 'z': no column named 'rz ' is present.rtr)r6rrlKeyErrorrr;rr<rr>rrrr7rr9r)r=r*ker-rIs r"rz ForeignKeyConstraint._set_parent s/tU+++  & 2 24 ? ? ? ?    K!!160A0A0A271:::O            4<77 2 2GC2x(( 2BIS,@,@,,S111 !!%(((((s9 B ?BB c ^td|jDfd|jD|j|j|j|j|j|j|j|j  }t|j|jD]\}}| || |S)Nc&g|]}|jjSr)rr+rs r"rz-ForeignKeyConstraint.copy.. s 1 1 1aQX\ 1 1 1r$cg|]I}|.||jjjkrjndJS)N)r!r)rrrr*r+r )rrr!r/s r"rz-ForeignKeyConstraint.copy.. sq   !#/ !(.*<<< ,00    r$)r r/rrrrr\r) rrr r/rrrrr\rrrW)r=r!r/r~rself_fkother_fks `` r"rTzForeignKeyConstraint.copys" 1 14= 1 1 1        ]]nn**'   *"%T]CL!A!A 0 0 GX  % %h / / / /%%c***r$) NNNNNFFNNNr)r]r^r_r`rarrrrrbrrrrrrrrTrr$r"rr sA  .N  O2O2O2O2b!!!G HFFXFX  - -X -X(++X+)))*++++++r$rcreZdZdZdZfdZfdZdZdZe dZ e j dZ xZS) ra A table-level PRIMARY KEY constraint. The :class:`.PrimaryKeyConstraint` object is present automatically on any :class:`_schema.Table` object; it is assigned a set of :class:`_schema.Column` objects corresponding to those marked with the :paramref:`_schema.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=, primary_key=True, nullable=False), Column('version_id', Integer(), table=, primary_key=True, nullable=False) ) The primary key of a :class:`_schema.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:`_schema.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:`_schema.Table` itself; columns marked as ``primary_key=True`` will be gathered into the empty constraint's column collection. primary_key_constraintc~|dd|_tt|j|i|dS)NrF)rrrrrr)r=rr~rs r"rzPrimaryKeyConstraint.__init__osC#%66*?#G#G 2"D))2GBrBBBBBr$c  tt|||j|ur@|j|j||_|j|d|jD}|jr|rt|t|j krtj d|j ddd|Dddd|jDddd |jDd g|dd<|jD]}d |_d |_|j|dS) Nc g|] }|j | Sr)rrs r"rz4PrimaryKeyConstraint._set_parent..{s99911=9Q999r$zTable 'z' specifies columns rc3*K|]}d|jzVdSr]rrs r"rz3PrimaryKeyConstraint._set_parent..s(AA!fqvoAAAAAAr$z= as primary_key=True, not matching locally specified columns c3*K|]}d|jzVdSr]rrs r"rz3PrimaryKeyConstraint._set_parent..(DD!fqvoDDDDDDr$z-; setting the current primary key columns to c3*K|]}d|jzVdSr]rrs r"rz3PrimaryKeyConstraint._set_parent..rr$z:. This warning may become an exception in a future releaseTF)rrrrrrUrr,rrvaluesrrr rr)extend)r=r* table_pksr,rs r"rz PrimaryKeyConstraint._set_parentss "D))55e<<<  D ( (   % %e&7 8 8 8 $E    ! !$ ' ' '99999 L  I#dl&9&9&;&;"<"<<< II JJJIIAAyAAAAAAAIIDDt|DDDDDDDIIDDt|DDDDDDD    IaaaL  A AMAJJ I&&&&&r$c|D] }d|_ |j|tj|||jdS)aKrepopulate 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:`_schema.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)rrrrr_resetr9r*)r=rr-s r"_reloadzPrimaryKeyConstraint._reloadse* # #C"COO G$$$299$??? &&tz22222r$ctj||j||j||dSr')rrrrr0rU'_sa_event_column_added_to_pk_constraintrvs r"rVzPrimaryKeyConstraint._replacesM299$??? S!!! ==dCHHHHHr$cl|jgfd|jDzSt|jS)Ncg|]}|u| Srr)rr,autoincs r"rz>PrimaryKeyConstraint.columns_autoinc_first..s#LLLa1G;K;K;K;K;Kr$)rrr)r=rs @r"columns_autoinc_firstz*PrimaryKeyConstraint.columns_autoinc_firstsE,  9LLLL4<LLLL L %% %r$chd}t|jdkrLt|jd}|jdur||d|S|jdvr||dr|SdSdSd}|jD]@}|jdur5||d|%t jd|jd|jd |}A|S) NcL|jj)t|jjtjjs$|r t jd|jd|ddSt|jtdtfs|sdS|j |sdS|j r |j dvrdSdS)Nz Column type z on column 'z+' is not compatible with autoincrement=TrueF)T ignore_fkT) r9_type_affinity issubclassr INTEGERTYPErr<r(r*r;r+rr0)r- autoinc_trues r"_validate_autoinczEPrimaryKeyConstraint._autoincrement_column.._validate_autoincsx&.j')=)L77. !++@C###O !5s{T$ZZ,BCC $ u#/ /u! c&7@''u4r$rrT)r1rFz=Only one Column may be marked autoincrement=True, found both rr)rrrr0rr<r )r=rr-rs r"rz*PrimaryKeyConstraint._autoincrement_columns%   2 t|   ! !t|$$Q'C D((!!#t,,, ! &%c511  G| & &$,,%%c4000*!// #xxx7 #&Nr$)r]r^r_r`rarrrrVrbrrrdrr#r$s@r"rr#sGGR.NCCCCC'''''B333:III &&X& 8888888r$rceZdZdZdZdS)rWaA 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. unique_constraintN)r]r^r_r`rarr$r"rWrWs)NNNr$rWcNeZdZdZdZdZdZedZd dZ d dZ d Z dS) ra 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:`_schema.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:`_schema.Column` objects:: Index("some_index", func.lower(sometable.c.name)) An :class:`.Index` can also be manually associated with a :class:`_schema.Table`, either through inline declaration or using :meth:`_schema.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:`_expression.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:`_expression.text` construct may be used to specify :class:`.Index` expressions, provided the :class:`.Index` is explicitly associated with the :class:`_schema.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. rcddx|_}g}g}||D]1\}}} } || ||2||_t ||dd|_|dd|_|dd} d|vr|d|_d|vr|d}| |tj |g|Rd| i|| |dSdS)aConstruct 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:`_schema.Column`, but may also be arbitrary SQL expressions which ultimately refer to a :class:`_schema.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:`_schema.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 ``_``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. NrPrFrrHr) r*rOrrrrrr rrHrrDrr) r=r rr~r*rprocessed_expressionsrrrLrNrs r"rzIndex.__init__Vsj@"! U "  4 4[ A A  / /     NN; ' ' ' ! ( ( . . . .0bffWd&;&;<< ffXu-- vvne44 R<<vDI r>>FF8$$E %%b))) &     )5        U # # # # #  r$c t|||j;||jur2tjd|jd|jjd|jd||_|j||j }| |}t|t|ksJdt||D|_ dS)NzIndex 'z' is against table 'z(', and cannot be associated with table 'r^cFg|]\}}t|tr|n|Sr)r(r)rrcolexprs r"rz%Index._set_parent..s?   gt]33 @DD   r$) rDrr*rr<r rrrrrhrr)r=r*rcol_expressionss r"rzIndex._set_parents))$666 : !e4:&=&=##999dj444e6G6G6GI    $& //66;3#7#77777  !$[/!B!B   r$c|jjS)z2Return the connectable associated with this Index.)r*rrLs r"rz Index.bindszr$Nch|t|}|tj||S)zIssue a ``CREATE`` statement for this :class:`.Index`, using the given :class:`.Connectable` for connectivity. .. seealso:: :meth:`_schema.MetaData.create_all`. rrs r"r z Index.creates4 <!$''D #-t444 r$ch|t|}|tj|dS)zIssue a ``DROP`` statement for this :class:`.Index`, using the given :class:`.Connectable` for connectivity. .. seealso:: :meth:`_schema.MetaData.drop_all`. Nr rs r"r z Index.drops5 <!$''D #+T22222r$cddt|jgd|jDz|jrdgpgzzS)Nz Index(%s)rc,g|]}t|Srr)res r"rz"Index.__repr__..s555q477555r$z unique=True)rrr rrrLs r"rMzIndex.__repr__s] IIdi!55D$45556;2M?8b:    r$r') r]r^r_r`rarrrbrr r rMrr$r"rrsIIVNB$B$B$H   (X     3 3 3 3     r$rixzix_%(column_0_label)scTeZdZdZdZejd ddZdZ dZ d Z d Z d Z d Z d ZdZdZejddZeeeZdZdZedZ ddZejdddZddZddZdS)MetaDataaDA collection of :class:`_schema.Table` objects and their associated schema constructs. Holds a collection of :class:`_schema.Table` objects as well as an optional binding to an :class:`_engine.Engine` or :class:`_engine.Connection`. If bound, the :class:`_schema.Table` objects in the collection and their columns may participate in implicit SQL execution. The :class:`_schema.Table` objects themselves are stored in the :attr:`_schema.MetaData.tables` dictionary. :class:`_schema.MetaData` is a thread-safe object for read operations. Construction of new tables within a single :class:`_schema.MetaData` object, either explicitly or via reflection, may not be completely thread-safe. .. seealso:: :ref:`metadata_describing` - Introduction to database metadata r)z0.8zThe :paramref:`_schema.MetaData.reflect` flag is deprecated and will be removed in a future release. Please use the :meth:`_schema.MetaData.reflect` method.)reflectNFcltj|_t|||_|r|nt |_|r||_t|_ i|_ tj t|_||_|r,|st!jd|dSdS)aCreate 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 :func:`_sa.create_engine` and this :class:`_schema.MetaData` will be bound to the resulting engine. :param reflect: Optional, automatically load all tables from the bound database. Defaults to False. :paramref:`_schema.MetaData.bind` is required when this option is set. :param schema: The default schema to use for the :class:`_schema.Table`, :class:`.Sequence`, and potentially other objects associated with this :class:`_schema.MetaData`. Defaults to ``None``. When this value is set, any :class:`_schema.Table` or :class:`.Sequence` which specifies ``None`` for the schema parameter will instead have this schema name defined. To build a :class:`_schema.Table` or :class:`.Sequence` that still has ``None`` for the schema even when this parameter is present, use the :attr:`.BLANK_SCHEMA` symbol. .. note:: As referred above, the :paramref:`_schema.MetaData.schema` parameter only refers to the **default value** that will be applied to the :paramref:`_schema.Table.schema` parameter of an incoming :class:`_schema.Table` object. It does not refer to how the :class:`_schema.Table` is catalogued within the :class:`_schema.MetaData`, which remains consistent vs. a :class:`_schema.MetaData` collection that does not define this parameter. The :class:`_schema.Table` within the :class:`_schema.MetaData` will still be keyed based on its schema-qualified name, e.g. ``my_metadata.tables["some_schema.my_table"]``. The current behavior of the :class:`_schema.ForeignKey` object is to circumvent this restriction, where it can locate a table given the table name alone, where the schema will be assumed to be present from this value as specified on the owning :class:`_schema.MetaData` collection. However, this implies that a table qualified with BLANK_SCHEMA cannot currently be referred to by string name from :class:`_schema.ForeignKey`. Other parts of SQLAlchemy such as Declarative may not have similar behaviors built in, however may do so in a future release, along with a consistent method of referring to a table in BLANK_SCHEMA. .. seealso:: :paramref:`_schema.Table.schema` :paramref:`.Sequence.schema` :param quote_schema: Sets the ``quote_schema`` flag for those :class:`_schema.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:`_schema.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:`_schema.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:`_schema.Table` object associated with the constraint. * ``%(referred_table_name)s`` - the name of the :class:`_schema.Table` object associated with the referencing target of a :class:`_schema.ForeignKeyConstraint`. * ``%(column_0_name)s`` - the name of the :class:`_schema.Column` at index position "0" within the constraint. * ``%(column_0N_name)s`` - the name of all :class:`_schema.Column` objects in order within the constraint, joined without a separator. * ``%(column_0_N_name)s`` - the name of all :class:`_schema.Column` objects in order within the constraint, joined with an underscore as a separator. * ``%(column_0_label)s``, ``%(column_0N_label)s``, ``%(column_0_N_label)s`` - the label of either the zeroth :class:`_schema.Column` or all :class:`.Columns`, separated with or without an underscore * ``%(column_0_key)s``, ``%(column_0N_key)s``, ``%(column_0_N_key)s`` - the key of either the zeroth :class:`_schema.Column` or all :class:`.Columns`, separated with or without an underscore * ``%(referred_column_0_name)s``, ``%(referred_column_0N_name)s`` ``%(referred_column_0_N_name)s``, ``%(referred_column_0_key)s``, ``%(referred_column_0N_key)s``, ... column tokens which render the names/keys/labels of columns that are referenced by a :class:`_schema.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 explicit 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:: 1.3.0 - added new ``%(column_0N_name)s``, ``%(column_0_N_name)s``, and related tokens that produce concatenations of names, keys, or labels for all columns referred to by a given constraint. .. seealso:: :ref:`constraint_naming_conventions` - for detailed usage examples. z8A bind must be supplied in conjunction with reflect=TrueN)r immutabledictrsrr!DEFAULT_NAMING_CONVENTIONnaming_conventionrHr_schemasr collections defaultdictrr[rrr<r)r=rrr!rrrHs r"rzMetaData.__init__sn(** !&,77 ! +  *   DI $066   '( LLNNNNN   r$cd|jzS)NzMetaData(bind=%r)rrLs r"rMzMetaData.__repr__s"TY..r$cVt|tjs|j}||jvSr')r(rr6r+rs)r= table_or_keys r"rpzMetaData.__contains__s,,(9:: ,'+Lt{**r$ct||}t|j|||r|j|dSdSr')r#dict __setitem__rsrr)r=r r!r*r+s r"rxzMetaData._add_tablesYT6** c5111  & M  f % % % % % & &r$c&t||}t|j|d}||jD]}|||jr7td|jD|_dSdS)Nc*g|]}|j |jSr'r)rts r"rz*MetaData._remove_table..s,x+H+++r$) r#rrrrsrrrrr)r=r r!r+removedrIs r"r|zMetaData._remove_tablesT6**((4;T22  * / /((.... = ![//11DMMM  r$cP|j|j|j|j|j|jdS)N)rsr!schemas sequencesfk_memosr)rsr!rrr[rrLs r" __getstate__zMetaData.__getstate__s0kk}!%!7    r$c|d|_|d|_|d|_d|_|d|_|d|_|d|_dS)Nrsr!rrrr)rsr!r_bindrrr[)r=states r" __setstate__zMetaData.__setstate__sUHo Ho !&':!;  ,i( z*r$c|jduS)z:True if this MetaData is bound to an Engine or Connection.NrrLs r"is_boundzMetaData.is_boundsz%%r$c|jS)a-An :class:`_engine.Engine` or :class:`_engine.Connection` to which this :class:`_schema.MetaData` is bound. Typically, a :class:`_engine.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" rrLs r"rz MetaData.bind s $zr$sqlalchemy.engine.urlct|tj|jfzrt j||_dS||_dS)z;Bind this MetaData to an Engine, Connection, string or URL.N)r(rr6URL sqlalchemy create_enginer)r=urlrs r"_bind_tozMetaData._bind_to!sC dD- : ; ; #1$77DJJJDJJJr$ct|j|j|jdS)z+Clear all Table objects from this MetaData.N)rclearrsrr[rLs r"rzMetaData.clear,sF 4;  r$cF||j|jdS)z1Remove the given Table object from this MetaData.N)r|r r!rs r"rzMetaData.remove3s$ 5:u|44444r$cxtjt|jdS)aReturns a list of :class:`_schema.Table` objects sorted in order of foreign key dependency. The sorting will place :class:`_schema.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:`.MetaData.sorted_tables` attribute cannot by itself accommodate automatic resolution of dependency cycles between tables, which are usually caused by mutually dependent foreign key constraints. When these cycles are detected, the foreign keys of these tables are omitted from consideration in the sort. A warning is emitted when this condition occurs, which will be an exception raise in a future release. Tables which are not part of the cycle will still be returned in dependency order. To resolve these cycles, the :paramref:`_schema.ForeignKeyConstraint.use_alter` parameter may be applied to those constraints which create a cycle. Alternatively, the :func:`_schema.sort_tables_and_constraints` function will automatically return foreign key constraints in a separate collection when cycles are detected so that they may be applied to a schema separately. .. versionchanged:: 1.3.17 - a warning is emitted when :attr:`.MetaData.sorted_tables` cannot perform a proper sort due to cyclical dependencies. This will be an exception in a future release. Additionally, the sort will continue to return other tables not involved in the cycle in dependency order which was not the case previously. .. seealso:: :func:`_schema.sort_tables` :func:`_schema.sort_tables_and_constraints` :attr:`_schema.MetaData.tables` :meth:`_reflection.Inspector.get_table_names` :meth:`_reflection.Inspector.get_sorted_table_and_fkc_names` c|jSr'r)rs r"rz(MetaData.sorted_tables..lsqur$r)r sort_tablesrrsrrLs r" sorted_tableszMetaData.sorted_tables8s9f 4;%%''__ = = =   r$Tc (|t}|5} d| ||td} | |j| d<t j|j| |r.|j | !t jfdD} n} tj fdt| D} nt j r fdt| D} n]fd D} | r>rd zpd }tjd |j|d d| dfdD} | D]G} t#|fi| #tj$r$}t jd|d|Yd}~@d}~wwxYw ddddS#1swxYwYdS)a 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 alternate schema. If None, the schema associated with this :class:`_schema.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:`_schema.Table` as :paramref:`_schema.Table.extend_existing`. .. versionadded:: 0.9.1 :param autoload_replace: Passed along to each :class:`_schema.Table` as :paramref:`_schema.Table.autoload_replace`. .. versionadded:: 0.9.1 :param resolve_fks: if True, reflect :class:`_schema.Table` objects linked to :class:`_schema.ForeignKey` objects located in each :class:`_schema.Table`. For :meth:`_schema.MetaData.reflect`, this has the effect of reflecting related tables that might otherwise not be in the list of tables being reflected, for example if the referenced table is in a different schema or is omitted via the :paramref:`.MetaData.reflect.only` parameter. When False, :class:`_schema.ForeignKey` objects are not followed to the :class:`_schema.Table` in which they link, however if the related table is also part of the list of tables that would be reflected in any case, the :class:`_schema.ForeignKey` object will still resolve to its related :class:`_schema.Table` after the :meth:`_schema.MetaData.reflect` operation is complete. Defaults to True. .. versionadded:: 1.3.0 .. seealso:: :paramref:`_schema.Table.resolve_fks` :param \**dialect_kwargs: Additional keyword arguments not mentioned above are dialect specific, and passed in the form ``_``. 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:`_schema.Table` objects reflected. NT)rrrkrrrr!)rcg|] }d| S)rr)rr r!s r"rz$MetaData.reflect..s$DDD$-DDDr$c&g|] \}}s|v |Srr)rr schnamecurrentrks r"rz$MetaData.reflect..s<%g&+2*@*@*@*@*@r$c>g|]\}}s|v ||Srr)rr rrrkonlyr=s r"rz$MetaData.reflect..sQ%g',3'+A+AT4((,B+A+A+Ar$cg|]}|v| Srr)rr availables r"rz$MetaData.reflect..s#JJJDD 4I4I44I4I4Ir$z schema '%s'rz7Could not reflect: requested table(s) not available in z: (rrc g|] }s|v| Srr)rr rrks r"rz$MetaData.reflect..s8&+/g*=*=*=*=*=r$zSkipping table z: )rconnectrr'r!r OrderedSetengine table_namesrget_view_namesrsrrrrurrfUnreflectableTableErrorr)r=rr!viewsrrkrrrconn reflect_optsavailable_w_schemaloadmissingsr uerrrrs` ` `` @@r"rzMetaData.reflectossz <!$''D \\^^A Ft!!%#2$4*!ee L    / / /~!)/ X& ''4'@@I L  !.adapt_listeners+\F HUFJv > > > > > >r$rrrNrrs ` r"rzMetaData.append_ddl_listenersM ? ? ? ? ?  T2 2 23 < <))'+t$#'DL s>4A65A6cHt|jdo |jjduS)z(True if there is a bind for this thread.r4N)r7r1r4rLs r"rzThreadLocalMetaData.is_bounds* DL) , , 1 $D0 r$c|jD]&}t|dr|'dS)z2Dispose all bound engines, in all thread contexts.disposeN)r2rr7r8)r=rs r"r8zThreadLocalMetaData.disposesK&&((  Aq)$$    r$)r]r^r_r`rarrrrrrbrr8r#r$s@r"r-r-Ws   N44444666T.//((0/(" 8D( # #D   r$r-cReZdZdZdZejdZdZe dZ dS)_SchemaTranslateMapaProvide translation of schema names based on a mapping. Also provides helpers for producing cache keys and optimized access when no mapping is present. Used by the :paramref:`.Connection.execution_options.schema_translate_map` feature. .. versionadded:: 1.1 )r[__call__hash_key is_defaultr!c_Pfd}|_dfdttD_d_dSd_j_d_dS)Nc^|}||}|Sr')_default_schema_getterr\)objrZr[r=s r"schema_for_objectz7_SchemaTranslateMap.__init__..schema_for_objects:#'#>#>s#C#C ##8$d$$ ('r$;c32K|]}|d|VdS)rNr)rrr[s r"rz/_SchemaTranslateMap.__init__..sC%%+,111d1gg&%%%%%%r$rFrT)r[r;rrrr<r=r@)r=r[rBs`` r"rz_SchemaTranslateMap.__init__s   ( ( ( ( ( (.DMHH%%%%06t0E0E0E%%%DM$DOOODM 7DM"DOOOr$c`|tSt|tr|St|Sr')_default_schema_mapr(r:)r}r[s r"_schema_getterz"_SchemaTranslateMap._schema_getters3 <& & 1 2 2 -K&t,, ,r$N) r]r^r_r` __slots__operator attrgetterr@rrjrGrr$r"r:r:sb  =I0X0::###*--[---r$r:cXeZdZdZdZedddd dZdZd Zd d Z dS) riaDefines a generated column, i.e. "GENERATED ALWAYS AS" syntax. The :class:`.Computed` construct is an inline construct added to the argument list of a :class:`_schema.Column` object:: from sqlalchemy import Computed Table('square', meta, Column('side', Float, nullable=False), Column('area', Float, Computed('side * side')) ) See the linked documentation below for complete details. .. versionadded:: 1.3.11 .. seealso:: :ref:`computed_ddl` computed_columnrz:class:`.Computed`z:paramref:`.Computed.sqltext`NcNt|d|_||_d|_dS)a Construct a GENERATED ALWAYS AS DDL construct to accompany a :class:`_schema.Column`. :param sqltext: A string containing the column generation expression, which will be used verbatim, or a SQL expression construct, such as a :func:`_expression.text` object. If given as a string, the object is converted to a :func:`_expression.text` object. :param persisted: Optional, controls how this column should be persisted by the database. Possible values are: * ``None``, the default, it will use the default persistence defined by the database. * ``True``, will render ``GENERATED ALWAYS AS ... STORED``, or the equivalent for the target database if supported. * ``False``, will render ``GENERATED ALWAYS AS ... VIRTUAL``, or the equivalent for the target database if supported. Specifying ``True`` or ``False`` may raise an error when the DDL is emitted to the target database if the database does not support that persistence option. Leaving this parameter at its default of ``None`` is guaranteed to succeed for all databases that support ``GENERATED ALWAYS AS``. TrN)rr persistedr)r=rrNs r"rzComputed.__init__s+@(MMM " r$ct|jtdtfr)t|jtdtfst jd||_||_||j_||j_dS)NzPA generated column cannot specify a server_default or a server_onupdate argument) r(r+r9rir,rr<rr8r;s r"rzComputed._set_parent s  !DJJ#9   F2T$ZZ4JKK #+  &* #%) """r$c|Sr'rrs r"r>zComputed._as_for_updates r$c t|j|j |jjnd|}t ||j}||S)N)rN)r3rrr*rirNrW)r=r/r~rgs r"rTz Computed.copysW" L!%!8DK  d    W 7 7 7%%a(((r$r') r]r^r_r`rar rrr>rTrr$r"riris,'N')HB * * *))))))r$ri)Er` __future__rrrIrrrrrbaserr r r rr r rrrrrrrwrrrrrsymbolrrqr#r3_self_inspects Visitabler5rfr)rrrmrrr:rr;r=r?deprecated_clsr3r6r@rBrDrlrrrrWrrrrr-r:rFrGrirr$r"rYs_.'&&&&& """"""############------&&&&&&######""""""######!!!!!! ###### O,, t{   ###BBB" B<B<B<B<B<"H$6B<B<B