L i-'@dZddlmZddlZddlmZddlmZddlmZddlm Z ddl m Z dd l m Z dd l m Z dd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z#dd l$m%Z%dd!l&m'Z'dd"l&m(Z(dd#l)m*Z*dd$l+m,Z,dd%l m-Z-dd&l.m/Z/er6dd'l0m1Z1dd(l0m2Z2dd)l0m3Z3dd*l0m4Z4dd+l0m5Z5dd,l0m6Z6dd-l0m7Z7dd.l0m8Z8dd/l0m9Z9ed0Z:e jv d=d1Z< d>d2Z=e Gd3d4eZ>e Gd5d6eZ?ejGd7d8ejd8ZBe/Gd9d:ZCeGd;d<ZDy)?aProvides an abstraction for obtaining database schema information. Usage Notes: Here are some general conventions when accessing the low level inspector methods such as get_table_names, get_columns, etc. 1. Inspector methods return lists of dicts in most cases for the following reasons: * They're both standard types that can be serialized. * Using a dict instead of a tuple allows easy expansion of attributes. * Using a list for the outer structure maintains order and is easy to work with (e.g. list comprehension [d['name'] for d in cols]). 2. Records that contain a name, such as the column name in a column record use the key 'name'. So for most return values, each record will have a 'name' attribute.. ) annotationsN) dataclass)auto)Flag)unique)Any)Callable) Collection)Dict) Generator)Iterable)List)Optional)Sequence)Set)Tuple) TYPE_CHECKING)TypeVar)Union) Connection)Engine)exc) inspection)sql)util) operators)schema)_ad_hoc_cache_key_from_args) quoted_name) TextClause) TypeEngine)InternalTraversal) topological)final)Dialect)ReflectedCheckConstraint)ReflectedColumn)ReflectedForeignKeyConstraint)ReflectedIndex)ReflectedPrimaryKeyConstraint)ReflectedTableComment)ReflectedUniqueConstraint)TableKey_Rc|jdd}| |||g|i|Sddh|jtd|Dtfd|jDf}|j|}||||g|i|}|||<|S)N info_cache unreflectablec3K|]=}t|tr+t|trt||jfn|?ywN) isinstancestrr!quote).0as b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/engine/reflection.py zcache..]s= !S!",A{!;SVQWW  B sAAc3K|]6\}}|vr-|t|trt||jfn|f8ywr5)r6r!r7r8)r9kvexcludes r;r<zcache..bsB 1Z;%?Q!Q G s.gors}VVL$/  dC-$-"- -)2;;.-N..% ;T3,,,C!JsO rM rEzCallable[..., _R]rFr'rGrrHrrIrreturnr0)r decorator)rPrQs` r; flexi_cacherUosZ ^^     " IrMc\eZdZdZeZ eZ eZ eezZ eezezZ y) ObjectKindaEnumerator that indicates which kind of object to return when calling the ``get_multi`` methods. This is a Flag enum, so custom combinations can be passed. For example, to reflect tables and plain views ``ObjectKind.TABLE | ObjectKind.VIEW`` may be used. .. note:: Not all dialect may support all kind of object. If a dialect does not support a particular object an empty dict is returned. In case a dialect supports an object, but the requested method is not applicable for the specified kind the default value will be returned for each reflected object. For example reflecting check constraints of view return a dict with all the views with empty lists as values. N) rB __module__ __qualname____doc__rTABLEVIEWMATERIALIZED_VIEWANY_VIEWANYrMr;rWrWsH" FE 6D &''H& $,* *C!rMrWc:eZdZdZeZ eZ eezZy) ObjectScopez]Enumerator that indicates which scope to use when calling the ``get_multi`` methods. N)rBrXrYrZrDEFAULT TEMPORARYr_r`rMr;rbrbs*fGI I C)rMrbceZdZUdZded<ded<ded<ded <d ed <ej d d dFdZe dGdZ dHdZ dIdZ dJdZ dKdZ eej d ddLdZej edLdZej edMdZej,dNdZej,dOdZedPdZdQdZ d# dRdZ d# dSdZ d# dTdZ d# dUd ZdVd!Z d# dWd"Z! dX dYd$Z"dQd%Z#dQd&Z$ d# dZd'Z%dde&jNe(jRf d[d(Z* d# dRd)Z+ d# dRd*Z, d# dRd+Z- d# d\d,Z. d# d]d-Z/ d^d.Z0dde&jNe(jRf d_d/Z1 d# d`d0Z2dde&jNe(jRf dad1Z3 d# dbd2Z4dde&jNe(jRf dcd3Z5 d# ddd4Z6dde&jNe(jRf ded5Z7 d# dfd6Z8dde&jNe(jRf dgd7Z9 d# dhd8Z:dde&jNe(jRf did9Z; d# djd:Z dnd=Z? dod>Z@ dpd?ZAeBjeBjeBjeBjd@ZG dqdAZH dqdBZI dqdCZJ drdDZK ds dtdEZLy)u Inspectora=Performs database schema inspection. The Inspector acts as a proxy to the reflection methods of the :class:`~sqlalchemy.engine.interfaces.Dialect`, providing a consistent interface as well as caching support for previously fetched metadata. A :class:`_reflection.Inspector` object is usually created via the :func:`_sa.inspect` function, which may be passed an :class:`_engine.Engine` or a :class:`_engine.Connection`:: from sqlalchemy import inspect, create_engine engine = create_engine("...") insp = inspect(engine) Where above, the :class:`~sqlalchemy.engine.interfaces.Dialect` associated with the engine may opt to return an :class:`_reflection.Inspector` subclass that provides additional methods specific to the dialect's target database. Union[Engine, Connection]bindrenginebool_op_context_requires_connectr'dialectzDict[Any, Any]r2z1.4aThe __init__() method on :class:`_reflection.Inspector` is deprecated and will be removed in a future release. Please use the :func:`.sqlalchemy.inspect` function on an :class:`_engine.Engine` or :class:`_engine.Connection` in order to acquire an :class:`_reflection.Inspector`.c&|j|y)aInitialize a new :class:`_reflection.Inspector`. :param bind: a :class:`~sqlalchemy.engine.Connection`, which is typically an instance of :class:`~sqlalchemy.engine.Engine` or :class:`~sqlalchemy.engine.Connection`. For a dialect-specific instance of :class:`_reflection.Inspector`, see :meth:`_reflection.Inspector.from_engine` N) _init_legacyrFrhs r;__init__zInspector.__init__s. $rMct|jdr|jj}|j|}||||S)N inspector)hasattrrlrr__new__)clsinitrhrFs r; _constructzInspector._constructs> 4<< -,,((C{{3 T4 rMcbt|dr|j|y|j|y)Nexec_driver_sql)rs_init_connection _init_engineros r;rnzInspector._init_legacys) 4* +  ! !$ '   d #rMc|x|_|_|jjd|_|jj |_i|_y)NT)rhriconnectcloserkrlr2)rFris r;r{zInspector._init_enginesC"(( DK ,0){{** rMc||_|j|_d|_|jj|_i|_y)NF)rhrirkrlr2)rF connections r;rzzInspector._init_connections6  '' ,1){{** rMc8|jjy)zreset the cache for this :class:`.Inspector`. Inspection methods that have data cached will emit SQL queries when next called to get new data. .. versionadded:: 2.0 N)r2clearrFs r; clear_cachezInspector.clear_cache s rMaThe from_engine() method on :class:`_reflection.Inspector` is deprecated and will be removed in a future release. Please use the :func:`.sqlalchemy.inspect` function on an :class:`_engine.Engine` or :class:`_engine.Connection` in order to acquire an :class:`_reflection.Inspector`.c:|j|j|S)aZConstruct a new dialect-specific Inspector object from the given engine or connection. :param bind: a :class:`~sqlalchemy.engine.Connection` or :class:`~sqlalchemy.engine.Engine`. This method differs from direct a direct constructor call of :class:`_reflection.Inspector` in that the :class:`~sqlalchemy.engine.interfaces.Dialect` is given a chance to provide a dialect-specific :class:`_reflection.Inspector` instance, which may provide additional methods. See the example at :class:`_reflection.Inspector`. )rwrn)rurhs r; from_enginezInspector.from_engines:~~c..55rMcJtjtj|Sr5)rfrwr{rhs r; _engine_inspzInspector._engine_insp7s##I$:$:DAArMcJtjtj|Sr5)rfrwrzrs r;_connection_inspzInspector._connection_insp;s##I$>$>EErMc#K|jr|jj}n |j} ||jr|jyy#|jr|jwwxYww)aReturn a context that optimizes for multiple operations on a single transaction. This essentially allows connect()/close() to be called if we detected that we're against an :class:`_engine.Engine` and not a :class:`_engine.Connection`. N)rkrhr}r~)rFconns r;_operation_contextzInspector._operation_context?sd  , ,99$$&D99D J00 1t00 1s4A;AA;A88A;c#K|j5}|j|jj|}|j|_|dddy#1swYyxYww)zReturn an :class:`_reflection.Inspector` from this one that will run all operations on a single connection. N)rrw __class__rzr2)rFrsub_insps r;_inspection_contextzInspector._inspection_contextTsU $ $ & $t~~'F'FMH"&//H N   sA$    *AAc |j5}|jj|||fd|ji|cdddS#1swYyxYw)aReturn True if the backend has a table, view, or temporary table of the given name. :param table_name: name of the table to check :param schema: schema name to query, if not the default schema. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. .. versionadded:: 1.4 - the :meth:`.Inspector.has_table` method replaces the :meth:`_engine.Engine.has_table` method. .. versionchanged:: 2.0:: :meth:`.Inspector.has_table` now formally supports checking for additional table-like objects: * any type of views (plain or materialized) * temporary tables of any kind Previously, these two checks were not formally specified and different dialects would vary in their behavior. The dialect testing suite now includes tests for all of these object types and should be supported by all SQLAlchemy-included dialects. Support among third party dialects may be lagging, however. r2N)rrl has_tabler2rF table_namerrIrs r;rzInspector.has_tablesV8 $ $ & $)4<<))j&59__HJ    +AAc |j5}|jj|||fd|ji|cdddS#1swYyxYw)aReturn True if the backend has a sequence with the given name. :param sequence_name: name of the sequence to check :param schema: schema name to query, if not the default schema. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. .. versionadded:: 1.4 r2N)rrl has_sequencer2)rF sequence_namerrIrs r;rzInspector.has_sequencesV $ $ & $,4<<,,mV8<KM   rc |j5}|jj||||fd|ji|cdddS#1swYyxYw)aCheck the existence of a particular index name in the database. :param table_name: the name of the table the index belongs to :param index_name: the name of the index to check :param schema: schema name to query, if not the default schema. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. .. versionadded:: 2.0 r2N)rrl has_indexr2)rFr index_namerrIrs r;rzInspector.has_indexs_& $ $ & $)4<<))   ??      s ,AAc |j5}|jj||fd|ji|cdddS#1swYyxYw)aTReturn True if the backend has a schema with the given name. :param schema_name: name of the schema to check :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. .. versionadded:: 2.0 r2N)rrl has_schemar2)rF schema_namerIrs r;rzInspector.has_schemasT $ $ & $*4<<**k.2ooAC   rc |j|fDcgc]*\}}|r|dnd|Dcgc] \\}}}||fc}}}f,c}}}}}Scc}}}wcc}}}}}w)agReturn dependency-sorted table and foreign key constraint names in referred to within a particular schema. This will yield 2-tuples of ``(tablename, [(tname, fkname), (tname, fkname), ...])`` consisting of table names in CREATE order grouped with the foreign key constraint names that are not detected as belonging to a cycle. The final element will be ``(None, [(tname, fkname), (tname, fkname), ..])`` which will consist of remaining foreign key constraint names that would require a separate CREATE step after-the-fact, based on dependencies between tables. :param schema: schema name to query, if not the default schema. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. .. seealso:: :meth:`_reflection.Inspector.get_table_names` :func:`.sort_tables_and_constraints` - similar method which works with an already-given :class:`_schema.MetaData`. )consider_schemasrN)%sort_tables_on_foreign_key_dependency)rFrrI table_key fk_collection_tnamefkss r;get_sorted_table_and_fkc_namesz(Inspector.get_sorted_table_and_fkc_namesswP;;"(<    !* ! t5BCC/*1ec%C   D  sA AA A r5c ttttf}t}t}i}g}|D]}|j|fi|} |j | | j D]U\\} } } | D chc]} | d c} ||| f<| D]0}| |dk7s ||dk7s|j|d|df|| ff2W ttj||}|D cgc]8\}} || f||| fj!d|DD cgc]} || f| f c} f:}} }} |dt|fgzScc} w#tj$rk}|jD]3|j|jfd|dD5ttj||}Yd}~d}~wwxYwcc} wcc} } }w)aReturn dependency-sorted table and foreign key constraint names referred to within multiple schemas. This method may be compared to :meth:`.Inspector.get_sorted_table_and_fkc_names`, which works on one schema at a time; here, the method is a generalization that will consider multiple schemas at once including that it will resolve for cross-schema foreign keys. .. versionadded:: 2.0 namereferred_tablereferred_schemac3,K|] }d|f yw)rNr`)r9fkcedges r;r<zBInspector.sort_tables_on_foreign_key_dependency..`s&'*T!WcN&srNc3&K|] \}}| ywr5r`)r9rrs r;r<zBInspector.sort_tables_on_foreign_key_dependency..msM!(DMs)rrr7setget_multi_foreign_keysextendrDaddlistr%sortrCircularDependencyErroredgesremoveupdate difference)rFrrI SchemaTabtuplesremaining_fkcsfknames_for_tabletnamesschname schema_fkeysrrfkeysfkfkeycandidate_sorterrrKrs @r;rz/Inspector.sort_tables_on_foreign_key_dependency(s?,(3-,- 365?BuAC"$' G6466wE"EL MM, '%1%7%7%9 ! EE).7#%BvJ7!7E"23" D&6!77"d+<&== %)):$;$()9$:!"")% 0     * D!+"2"266"BCN.%3   !%% 0%0@ALLM,:Mu%r*     tT.12333W7&** D   d#%%&.?Q.H&  "+"2"266"BCN D  s7: D?E-*G  G$G GA!F==GG c |j5}|jj|fd|ji|cdddS#1swYyxYw)aReturn a list of temporary table names for the current bind. This method is unsupported by most dialects; currently only Oracle Database, PostgreSQL and SQLite implements it. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. r2N)rrlget_temp_table_namesr2rs r;rzInspector.get_temp_table_namesvsR $ $ & $44<<44!%46   rc |j5}|jj|fd|ji|cdddS#1swYyxYw)anReturn a list of temporary view names for the current bind. This method is unsupported by most dialects; currently only PostgreSQL and SQLite implements it. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. r2N)rrlget_temp_view_namesr2rs r;rzInspector.get_temp_view_namessR $ $ & $34<<33!%46   rc |j5}|jj|||fd|ji|cdddS#1swYyxYw)azReturn a dictionary of options specified when the table of the given name was created. This currently includes some options that apply to MySQL and Oracle Database tables. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dict with the table options. The returned keys depend on the dialect in use. Each one is prefixed with the dialect name. .. seealso:: :meth:`Inspector.get_multi_table_options` r2N)rrlget_table_optionsr2rs r;rzInspector.get_table_optionssV4 $ $ & $14<<11j&59__HJ   rc |j5}|jj|f|||||jd|}t |cdddS#1swYyxYw)aReturn a dictionary of options specified when the tables in the given schema were created. The tables can be filtered by passing the names to use to ``filter_names``. This currently includes some options that apply to MySQL and Oracle tables. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if options of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are dictionaries with the table options. The returned keys in each dict depend on the dialect in use. Each one is prefixed with the dialect name. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_table_options` r filter_nameskindscoper2N)rrlget_multi_table_optionsr2dict)rFrrrrrIrress r;rz!Inspector.get_multi_table_optionsslZ $ $ & $6$,,66)?? C9   s 8AAc |j5}|jj||fd|ji|cdddS#1swYyxYw)aReturn all non-materialized view names in `schema`. :param schema: Optional, retrieve names from a non-default schema. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. .. versionchanged:: 2.0 For those dialects that previously included the names of materialized views in this list (currently PostgreSQL), this method no longer returns the names of materialized views. the :meth:`.Inspector.get_materialized_view_names` method should be used instead. .. seealso:: :meth:`.Inspector.get_materialized_view_names` r2N)rrlget_view_namesr2rs r;rzInspector.get_view_namessT0 $ $ & $.4<<..f)-<>   rc |j5}|jj||fd|ji|cdddS#1swYyxYw)aReturn all materialized view names in `schema`. :param schema: Optional, retrieve names from a non-default schema. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. .. versionadded:: 2.0 .. seealso:: :meth:`.Inspector.get_view_names` r2N)rrlget_materialized_view_namesr2rs r;rz%Inspector.get_materialized_view_names sT& $ $ & $;4<<;;f)-<>   rc |j5}|jj||fd|ji|cdddS#1swYyxYw)akReturn all sequence names in `schema`. :param schema: Optional, retrieve names from a non-default schema. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. r2N)rrlget_sequence_namesr2rs r;rzInspector.get_sequence_names$sT $ $ & $24<<22f)-<>   rc |j5}|jj|||fd|ji|cdddS#1swYyxYw)aReturn definition for the plain or materialized view called ``view_name``. :param view_name: Name of the view. :param schema: Optional, retrieve names from a non-default schema. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. r2N)rrlget_view_definitionr2)rF view_namerrIrs r;rzInspector.get_view_definition6sV $ $ & $34<<33i48OOGI   rc |j5}|jj|||fd|ji|}dddr|j |g|S#1swYxYw)aJReturn information about columns in ``table_name``. Given a string ``table_name`` and an optional string ``schema``, return column information as a list of :class:`.ReflectedColumn`. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: list of dictionaries, each representing the definition of a database column. .. seealso:: :meth:`Inspector.get_multi_columns`. r2N)rrl get_columnsr2_instantiate_types)rFrrrIrcol_defss r;rzInspector.get_columnsJsr4 $ $ & $/t||//j&59__HJH    # #XJ /   s ,AA$c`|D])}|D]"}|d}t|tr||d<$+y)Ntype)r6r#)rFdatarcol_defcoltypes r;rzInspector._instantiate_typesls@ 0H# 0!&/!':6&-iGFO 0 0rMc |j5}t|jj|f|||||jd|}ddd|j j |S#1swY*xYw)aWReturn information about columns in all objects in the given schema. The objects can be filtered by passing the names to use to ``filter_names``. For each table the value is a list of :class:`.ReflectedColumn`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if columns of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are list of dictionaries, each representing the definition of a database column. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_columns` rN)rrrlget_multi_columnsr2rvalues)rFrrrrrIrtable_col_defss r;rzInspector.get_multi_columnsvsX $ $ & $!. ..!!-#  N   5 5 78  s 7A11A:c |j5}|jj|||fd|ji|cdddS#1swYyxYw)a`Return information about primary key constraint in ``table_name``. Given a string ``table_name``, and an optional string `schema`, return primary key information as a :class:`.ReflectedPrimaryKeyConstraint`. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary representing the definition of a primary key constraint. .. seealso:: :meth:`Inspector.get_multi_pk_constraint` r2N)rrlget_pk_constraintr2rs r;rzInspector.get_pk_constraintsV0 $ $ & $14<<11j&59__HJ   rc |j5}t|jj|f|||||jd|cdddS#1swYyxYw)auReturn information about primary key constraints in all tables in the given schema. The tables can be filtered by passing the names to use to ``filter_names``. For each table the value is a :class:`.ReflectedPrimaryKeyConstraint`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if primary keys of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are dictionaries, each representing the definition of a primary key constraint. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_pk_constraint` rN)rrrlget_multi_pk_constraintr2rFrrrrrIrs r;rz!Inspector.get_multi_pk_constraintsiV $ $ & $4 44!!-#      6AAc |j5}|jj|||fd|ji|cdddS#1swYyxYw)agReturn information about foreign_keys in ``table_name``. Given a string ``table_name``, and an optional string `schema`, return foreign key information as a list of :class:`.ReflectedForeignKeyConstraint`. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a list of dictionaries, each representing the a foreign key definition. .. seealso:: :meth:`Inspector.get_multi_foreign_keys` r2N)rrlget_foreign_keysr2rs r;rzInspector.get_foreign_keyssV4 $ $ & $04<<00j&59__HJ   rc |j5}t|jj|f|||||jd|cdddS#1swYyxYw)aoReturn information about foreign_keys in all tables in the given schema. The tables can be filtered by passing the names to use to ``filter_names``. For each table the value is a list of :class:`.ReflectedForeignKeyConstraint`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if foreign keys of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are list of dictionaries, each representing a foreign key definition. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_foreign_keys` rN)rrrlrr2rs r;rz Inspector.get_multi_foreign_keys%siZ $ $ & $3 33!!-#     rc |j5}|jj|||fd|ji|cdddS#1swYyxYw)a=Return information about indexes in ``table_name``. Given a string ``table_name`` and an optional string `schema`, return index information as a list of :class:`.ReflectedIndex`. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a list of dictionaries, each representing the definition of an index. .. seealso:: :meth:`Inspector.get_multi_indexes` r2N)rrl get_indexesr2rs r;rzInspector.get_indexes_sV2 $ $ & $+4<<++j&59__HJ   rc |j5}t|jj|f|||||jd|cdddS#1swYyxYw)aPReturn information about indexes in in all objects in the given schema. The objects can be filtered by passing the names to use to ``filter_names``. For each table the value is a list of :class:`.ReflectedIndex`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if indexes of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are list of dictionaries, each representing the definition of an index. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_indexes` rN)rrrlget_multi_indexesr2rs r;rzInspector.get_multi_indexes}siX $ $ & $. ..!!-#     rc |j5}|jj|||fd|ji|cdddS#1swYyxYw)a~Return information about unique constraints in ``table_name``. Given a string ``table_name`` and an optional string `schema`, return unique constraint information as a list of :class:`.ReflectedUniqueConstraint`. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a list of dictionaries, each representing the definition of an unique constraint. .. seealso:: :meth:`Inspector.get_multi_unique_constraints` r2N)rrlget_unique_constraintsr2rs r;rz Inspector.get_unique_constraintssV4 $ $ & $64<<66j&59__HJ   rc |j5}t|jj|f|||||jd|cdddS#1swYyxYw)aReturn information about unique constraints in all tables in the given schema. The tables can be filtered by passing the names to use to ``filter_names``. For each table the value is a list of :class:`.ReflectedUniqueConstraint`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if constraints of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are list of dictionaries, each representing the definition of an unique constraint. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_unique_constraints` rN)rrrlget_multi_unique_constraintsr2rs r;rz&Inspector.get_multi_unique_constraintssiZ $ $ & $9 99!!-#     rc |j5}|jj|||fd|ji|cdddS#1swYyxYw)aReturn information about the table comment for ``table_name``. Given a string ``table_name`` and an optional string ``schema``, return table comment information as a :class:`.ReflectedTableComment`. Raises ``NotImplementedError`` for a dialect that does not support comments. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary, with the table comment. .. versionadded:: 1.2 .. seealso:: :meth:`Inspector.get_multi_table_comment` r2N)rrlget_table_commentr2rs r;r zInspector.get_table_commentsV: $ $ & $14<<11j&59__HJ   rc |j5}t|jj|f|||||jd|cdddS#1swYyxYw)aReturn information about the table comment in all objects in the given schema. The objects can be filtered by passing the names to use to ``filter_names``. For each table the value is a :class:`.ReflectedTableComment`. Raises ``NotImplementedError`` for a dialect that does not support comments. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if comments of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are dictionaries, representing the table comments. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_table_comment` rN)rrrlget_multi_table_commentr2rs r;r z!Inspector.get_multi_table_comment1si^ $ $ & $4 44!!-#     rc |j5}|jj|||fd|ji|cdddS#1swYyxYw)ayReturn information about check constraints in ``table_name``. Given a string ``table_name`` and an optional string `schema`, return check constraint information as a list of :class:`.ReflectedCheckConstraint`. :param table_name: string name of the table. For special quoting, use :class:`.quoted_name`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a list of dictionaries, each representing the definition of a check constraints. .. seealso:: :meth:`Inspector.get_multi_check_constraints` r2N)rrlget_check_constraintsr2rs r;r zInspector.get_check_constraintsmsV4 $ $ & $54<<55j&59__HJ   rc |j5}t|jj|f|||||jd|cdddS#1swYyxYw)aReturn information about check constraints in all tables in the given schema. The tables can be filtered by passing the names to use to ``filter_names``. For each table the value is a list of :class:`.ReflectedCheckConstraint`. :param schema: string schema name; if omitted, uses the default schema of the database connection. For special quoting, use :class:`.quoted_name`. :param filter_names: optionally return information only for the objects listed here. :param kind: a :class:`.ObjectKind` that specifies the type of objects to reflect. Defaults to ``ObjectKind.TABLE``. :param scope: a :class:`.ObjectScope` that specifies if constraints of default, temporary or any tables should be reflected. Defaults to ``ObjectScope.DEFAULT``. :param \**kw: Additional keyword argument to pass to the dialect specific implementation. See the documentation of the dialect in use for more information. :return: a dictionary where the keys are two-tuple schema,table-name and the values are list of dictionaries, each representing the definition of a check constraints. The schema is ``None`` if no schema is provided. .. versionadded:: 2.0 .. seealso:: :meth:`Inspector.get_check_constraints` rN)rrrlget_multi_check_constraintsr2rs r;rz%Inspector.get_multi_check_constraintssiZ $ $ & $8 88!!-#     rc |||vry|j||jj}|j5}|j |} ddd|j } |j D cic],} | |jvr| |jj| .} }  | f} || |jvr?|j| f| gtjtj|d|j}| |jvr|j| | |jvrtj | |j"r.|j"j| }|r|j%|d}i}|j| D]}d}|j'||||||s'|j)| | stj | |j+|| ||||j-|| ||||||| |j/|| ||||| |j1|| ||||| |j3|| ||||| |j5|| || y#1swYxYwcc} w)aZGiven a :class:`_schema.Table` object, load its internal constructs based on introspection. This is the underlying method used by most dialects to produce table reflection. Direct usage is like:: from sqlalchemy import create_engine, MetaData, Table from sqlalchemy import inspect engine = create_engine("...") meta = MetaData() user_table = Table("user", meta) insp = inspect(engine) insp.reflect_table(user_table, None) .. versionchanged:: 1.4 Renamed from ``reflecttable`` to ``reflect_table`` :param table: a :class:`~sqlalchemy.schema.Table` instance. :param include_columns: a list of string column names to include in the reflection process. If ``None``, all columns are reflected. N)rrr _reflect_infoFT)rrhrlrschema_for_objectrreflection_optionsdialect_kwargsrAcolumns_get_reflection_inforWr_rbr3rNoSuchTableError table_options_validate_dialect_kwargs_reflect_columnr _reflect_pk _reflect_fk_reflect_indexes_reflect_unique_constraints_reflect_check_constraints_reflect_table_comment)rFtableinclude_columnsexclude_columns resolve_fks _extend_onrrlrrrr>rrtbl_opts found_tablecols_by_orig_namecol_ds r; reflect_tablezInspector.reflect_tablesB  ! "u%))##  $ $ & 3$++E2F 3ZZ // E((( u##''* *  Z(  I]5J5J$J5D55(\^^!oo+  && M  33 3--i8 8 M11 1&&z2 2  & &$2266yAH..x8 >@"**95 EK  !   4>>*f#E&&z2 2  9e->                      ((         ''         ##      O 3 3 sI31I Ic|d}|jjj||||jj||||d}|r||vs|r||vry|d}dD cic] } | |vr| || } } d|vr| j|dg} |j d|d} | Jt | t rtj| d} nGt | tjs+tjtj| d} n| } | j| d|vr)tjd i|d}| j|d |vr)tjd i|d }| j|tj||g| i| x||<}|j |j"vrd|_|j%|d ycc} w) Nrr)nullable autoincrementr8inforJcommentdialect_optionsdefaultT) _reflectedcomputedidentity)replace_existingr`)metadatadispatchcolumn_reflectrrAr6r" sa_schema DefaultClause FetchedValuertextappendComputedIdentityColumnrJ primary_key append_column)rFr!r)r"r#r( orig_namerrr>col_kwcolargs default_textr1r3r4cols r;rzInspector._reflect_column]s&M  ..tUEB %%dE59V} O ;  7 -  Ez uQxK      % MM% 12 3 99Y  + +L+ ++, 3#11 T i.D.DE#11HH\*t' NN7 #   ))>E*,=>H NN8 $   ))>E*,=>H NN8 $-6-=-= '. #. '-.  )$s 77e'' '"CO C$7_  s%Gc|jj|}|r|dDcgc]}||vr ||vr||}}|jd|j_|jdd|j_|jd} | r%|jj j | |jj|yycc}w)Nconstrained_columnsrr/r0) pk_constraintrArArr/rr_reload) rFrrr!r(r#pk_conspkpk_colsr0s r;rzInspector._reflect_pks --11)< ""78**r/H""%G&-[[%8E   "(/ It(DE   %%kk*;t j||jf|jt j||d| |D]$}|jdj||g&d | vr| d }ni} |jt j||| fd | jd d |ycc} w#tj $r<t#j$d |j&d| ddj|dYwxYw)NrrIrrreferred_columns)r autoload_withr%r.)rQrr%roptionsTr/) link_to_namer/zOn reflected table z0, skipping reflection of foreign key constraint z-; one or more subject columns within name(s) z, z are not present in the table) foreign_keysrArJr intersectionrr9Tabler6rhr=join BLANK_SCHEMAappend_constraintForeignKeyConstraintrConstraintColumnNotFoundErrorrwarnr)rFrrr!r(r"r#r$r%rrfkey_dconnamecrIrrrPrefspeccolumnrSs r;rzInspector._reflect_fkso**..y"=J FVnG  56#-.1B,B!!$((I# #  +,99/J#/0;;OL$%67O#$45N%&89 G*OO& /&*ii#-&3 -/FNN/>6!JK OO&'+ii(55#-&3 -/GFNN388^V,D#EFGF" + ''22+&* & 9 5  "  sJ #~44  )%**6.i #yy)<=>?++ sF),9F..A G=<G=)ascdesc nulls_first nulls_lastc ~|jj|g}|D]d} | d} | d} | jd} | jdi} | d}| jdd}| jdi}| jd }|rt| j|s|rg}t | D]\}}|?| s$t j d |d | d |d zdtj| |}nW ||vr||}n|j|}| j|dD](}||jvs|j|}||}*|j|tj| g|||d|gy#t$r+t j |d|d|jYwxYw)Nr column_names expressionscolumn_sortingrrindexr0duplicates_constraintz Skipping  z because key rz5 reflected as None but no 'expressions' were returnedz key z& was not located in columns for table r`)_tabler)indexesrArissubset enumeraterr]rr<r`KeyErrorr_index_sort_exprsr=r9Index)rFrrr!r(r"r#rroindex_drrrirjrflavorr0 duplicates idx_elementsrkr` idx_elementoptionops r;rzInspector._reflect_indexes s ''++Ir:4 G6?Dn-G!++m4K$[[)92>NX&F[[1F%kk*;R@O %<=Js7|'<'<_'ML%g." q9& 'xq $qyk*:: "%((;u+=">K ! 11*;A*>K*/''!*K#1"4"4Q";:!T%;%;;!%!7!7!?B*,[/K:##K05" 8!!!  & ]4 D$! %heA51116@! !s?F0F<;F<c $|jj|g}|D]} | d} | d} | jd} | jd} | jdi}|rt| j|s^| rag}| D],} ||vr||n|j|}|j |.|jtj|| | d |y#t $r)tjd|d|jdYwxYw) Nrrhr/duplicates_indexr0zunique constraint key 'z(' was not located in columns for table '')rr/) unique_constraintsrArrpr`r=rrrr]rrZr9UniqueConstraint)rFrrr!r(r"r#r constraintsconst_dr_rr/rwr0constrained_colsr`constrained_cols r;rz%Inspector._reflect_unique_constraintsbs7$66::9bI "" GfoGn-Gkk),G %78J%kk*;R@Os7|'<'<_'M "  = = 11*!,"WWQZ$%++O< =  # #**% #&  7" ( II45uzzCsC/DDc|jj|g}|D]&} |jtjdi| (y)Nr`)check_constraintsrArZr9CheckConstraint) rFrrr!r(r"r#rrrs r;rz$Inspector._reflect_check_constraintssI$5599)RH " JG  # #I$=$=$H$H I JrMcT|jj|}|r |d|_yyNr<) table_commentrAr/)rFrrr!r comment_dicts r;r z Inspector._reflect_table_comments.%2266yA (0EM rMc  |d<r(|r&tdkDrtt|z nd ixd<}d ddd d  fd}t|jd|j|j|j |j d |jd |jd |jd | }|r|j||S|S) Nrdr3TF)optionalcheck_filter_names_from_methc*dks% jj|js}nd} r|dd|i}|r |sd |Si}|S#t$r |si}Y|SwxYw)Ng?rFr`)rl_overrides_defaultrBNotImplementedError) methrr_fnrrfraction has_resultrIrFs r;runz+Inspector._get_reflection_info..runs s?||66t}}E" 6C626C3C&+ J C J ' J  sA A AA)r)r) rrJrUrorrrrr3)rrrrjrrjrSr) len_ReflectionInforrrrrr rrr) rFrr availablerrIr3rr.rrs ` ` ` @@r;rzInspector._get_reflection_infos<8 I#l*;c*A<(3y>9HH/10?m #16 ! ! ! +/ !   ! ! F&&Td::;T889../"11D d::TJ!004d::TJ' "    & KrM)rhrg)rvzCallable[..., Any]rhrgrSrf)rhrgrSNone)rirrSr)rrrSr)rSr)rhrrSrf)rhrrSrf)rSz!Generator[Connection, None, None])rSz Generator[Inspector, None, None])rS Optional[str])rIrrS List[str])rrrIrrSr)rr7rrrIrrSrj)rr7rrrIrrSrj) rr7rr7rrrIrrSrj)rr7rIrrSrj)rrrIrrSz;List[Tuple[Optional[str], List[Tuple[str, Optional[str]]]]])r5)rzCollection[Optional[str]]rIrrSzgList[Tuple[Optional[Tuple[Optional[str], str]], List[Tuple[Tuple[Optional[str], str], Optional[str]]]]])rr7rrrIrrSDict[str, Any]) rrrOptional[Sequence[str]]rrWrrbrIrrSDict[TableKey, Dict[str, Any]])rr7rrrIrrSr7)rr7rrrIrrSList[ReflectedColumn])rzIterable[List[ReflectedColumn]]rSr) rrrrrrWrrbrIrrS%Dict[TableKey, List[ReflectedColumn]])rr7rrrIrrSr,) rrrrrrWrrbrIrrSz-Dict[TableKey, ReflectedPrimaryKeyConstraint])rr7rrrIrrS#List[ReflectedForeignKeyConstraint]) rrrrrrWrrbrIrrS3Dict[TableKey, List[ReflectedForeignKeyConstraint]])rr7rrrIrrSList[ReflectedIndex]) rrrrrrWrrbrIrrS$Dict[TableKey, List[ReflectedIndex]])rr7rrrIrrSList[ReflectedUniqueConstraint]) rrrrrrWrrbrIrrS/Dict[TableKey, List[ReflectedUniqueConstraint]])rr7rrrIrrSr-) rrrrrrWrrbrIrrSz%Dict[TableKey, ReflectedTableComment])rr7rrrIrrSList[ReflectedCheckConstraint]) rrrrrrWrrbrIrrS.Dict[TableKey, List[ReflectedCheckConstraint]])r`TNN)r!sa_schema.Tabler"Optional[Collection[str]]r#Collection[str]r$rjr%Optional[Set[sa_schema.Table]]rOptional[_ReflectionInfo]rSr) r!rr)r)r"rr#rr( Dict[str, sa_schema.Column[Any]]rSr) rrrr/r!rr(rr#rrSr)rrrr/r!rr(rr"rr#rr$rjr%rrrrSr)rrrr/r!rr(rr"rr#rrrrSr) rrrr/r!rrrrSr)NNNN) rrrrrrrrrIrrSr)MrBrXrYrZ__annotations__r deprecatedrp classmethodrwrnr{rzrrr _inspectsrrrr contextlibcontextmanagerrrpropertyrrrrrrrrrrrrrWr[rbrcrrrrrrrrrrrrrrrrr r r rr*rrrrasc_opdesc_opnulls_first_op nulls_last_oprsrrrr rr`rMr;rfrfsJ 0 $# N"&& T__  5      %-F $   T__  5 6 6&Z&!B"BZ*%F&F(  00 '+#25 D8<'4CF D;? *7FI .!%      :$!%+ + +  E + ^7>L43L4L4  L4\""8<'4CF B!%04%++(00 77.7 7  7  7 (7t'+#25 <'+#25 2'+#25 &7;&3BE *8<  '4 CF   D030 0!%04%++(00 99.9 9  9  9 /9x8<'4CF &>!%04%++(00 66.6 6  6  6 76r8<'4CF ,B!%04%++(00 88.8 8  8  8 =8v8<'4CF @!%04%++(00 77.7 7  7  7 .7t8<'4CF (B!%04%++(00 88.8 8  8  8 98v8<  '4 CF   H!%04%++(00 ::.: :  :  : /:z8<'4CF 'B!%04%++(00 88.8 8  8  8 88|,. 5937U U 3U ) U  U 3 U 1U  U nF8F8F83 F8 ) F8 < F8 F8P/&// / < / ) / /6W&WW W < W 3 W)WW3W+W Wt!! //-- @&@@ @ < @ 3 @)@+@ @D.&.. . < . 3 .).+. .` J& J J J < J 3 J) J+ J  J 1& 1 1 1 + 1  1!%26/337 LL0L- L 1 L  L LrMrfceZdZdZed dZed dZed dZeddZeddZ eddZ eddZ edd Z y )ReflectionDefaultsz5provides blank default values for reflection methods.cgSr5r`rus r;rzReflectionDefaults.columns rMc dgdS)N)rrIr`rs r;rJz ReflectionDefaults.pk_constraints#%  rMcgSr5r`rs r;rUzReflectionDefaults.foreign_keys rrMcgSr5r`rs r;rozReflectionDefaults.indexes rrMcgSr5r`rs r;rz%ReflectionDefaults.unique_constraintsrrMcgSr5r`rs r;rz$ReflectionDefaults.check_constraintsrrMciSr5r`rs r;rz ReflectionDefaults.table_optionsrrMc ddiSrr`rs r;rz ReflectionDefaults.table_comments ~rMN)rSr)rSr,)rSr)rSr)rSr)rSr)rSr)rSr-) rBrXrYrZrrrJrUrorrrrr`rMr;rrs?  rMrcpeZdZUded<ded<ded<ded<d ed <d ed <d ed<ded<ded<ddZy)rrrz7Dict[TableKey, Optional[ReflectedPrimaryKeyConstraint]]rJrrUrrorrz/Dict[TableKey, Optional[ReflectedTableComment]]rrrrrz+Dict[TableKey, exc.UnreflectableTableError]r3c|jjD]5\}}t||}||t|||%|j |7yr5)__dict__rDgetattrsetattrr)rFotherr>r?ovs r;rz_ReflectionInfo.update/sOMM'') !DAq"B~9D!R(HHRL  !rMN)rrrSr)rBrXrYrrr`rMr;rr"s= 22JJEE 11GGBBEE11>>!rMrrR)rPzTuple[str, InternalTraversal]rSz0Callable[[Callable[..., _R]], Callable[..., _R]])ErZ __future__rr dataclassesrenumrrrtypingrr r r r r rrrrrrrrbaserrrrrrrrr9 sql.cache_keyr sql.elementsr!r" sql.type_apir# sql.visitorsr$r% util.typingr& interfacesr'r(r)r*r+r,r-r.r/r0rTrLrUrWrb_self_inspects Inspectablerfrrr`rMr;rs&#! %7&%%,#4+9*915$ T]        >150"""> *$ * * A &&{3AAH:$$$N !! !rM