MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / reflect_table

Method reflect_table

lib/sqlalchemy/engine/reflection.py:1477–1626  ·  view source on GitHub ↗

Given 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

(
        self,
        table: sa_schema.Table,
        include_columns: Optional[Collection[str]],
        exclude_columns: Collection[str] = (),
        resolve_fks: bool = True,
        _extend_on: Optional[Set[sa_schema.Table]] = None,
        _reflect_info: Optional[_ReflectionInfo] = None,
    )

Source from the content-addressed store, hash-verified

1475 )
1476
1477 def reflect_table(
1478 self,
1479 table: sa_schema.Table,
1480 include_columns: Optional[Collection[str]],
1481 exclude_columns: Collection[str] = (),
1482 resolve_fks: bool = True,
1483 _extend_on: Optional[Set[sa_schema.Table]] = None,
1484 _reflect_info: Optional[_ReflectionInfo] = None,
1485 ) -> None:
1486 """Given a :class:`_schema.Table` object, load its internal
1487 constructs based on introspection.
1488
1489 This is the underlying method used by most dialects to produce
1490 table reflection. Direct usage is like::
1491
1492 from sqlalchemy import create_engine, MetaData, Table
1493 from sqlalchemy import inspect
1494
1495 engine = create_engine("...")
1496 meta = MetaData()
1497 user_table = Table("user", meta)
1498 insp = inspect(engine)
1499 insp.reflect_table(user_table, None)
1500
1501 .. versionchanged:: 1.4 Renamed from ``reflecttable`` to
1502 ``reflect_table``
1503
1504 :param table: a :class:`~sqlalchemy.schema.Table` instance.
1505 :param include_columns: a list of string column names to include
1506 in the reflection process. If ``None``, all columns are reflected.
1507
1508 """
1509
1510 if _extend_on is not None:
1511 if table in _extend_on:
1512 return
1513 else:
1514 _extend_on.add(table)
1515
1516 dialect = self.bind.dialect
1517
1518 with self._operation_context() as conn:
1519 schema = conn.schema_for_object(table)
1520
1521 table_name = table.name
1522
1523 # get table-level arguments that are specifically
1524 # intended for reflection, e.g. oracle_resolve_synonyms.
1525 # these are unconditionally passed to related Table
1526 # objects
1527 reflection_options = {
1528 k: table.dialect_kwargs.get(k)
1529 for k in dialect.reflection_options
1530 if k in table.dialect_kwargs
1531 }
1532
1533 table_key = (schema, table_name)
1534 if _reflect_info is None or table_key not in _reflect_info.columns:

Callers 2

_autoloadMethod · 0.80
test_unreflectableMethod · 0.80

Calls 14

_operation_contextMethod · 0.95
_get_reflection_infoMethod · 0.95
_reflect_columnMethod · 0.95
has_tableMethod · 0.95
_reflect_pkMethod · 0.95
_reflect_fkMethod · 0.95
_reflect_indexesMethod · 0.95
addMethod · 0.45

Tested by 1

test_unreflectableMethod · 0.64