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