Called for each unit of 'column info' retrieved when a :class:`_schema.Table` is being reflected. This event is most easily used by applying it to a specific :class:`_schema.MetaData` instance, where it will take effect for all :class:`_schema.Table` objects within t
(
self, inspector: Inspector, table: Table, column_info: ReflectedColumn
)
| 348 | """ |
| 349 | |
| 350 | def column_reflect( |
| 351 | self, inspector: Inspector, table: Table, column_info: ReflectedColumn |
| 352 | ) -> None: |
| 353 | """Called for each unit of 'column info' retrieved when |
| 354 | a :class:`_schema.Table` is being reflected. |
| 355 | |
| 356 | This event is most easily used by applying it to a specific |
| 357 | :class:`_schema.MetaData` instance, where it will take effect for |
| 358 | all :class:`_schema.Table` objects within that |
| 359 | :class:`_schema.MetaData` that undergo reflection:: |
| 360 | |
| 361 | metadata = MetaData() |
| 362 | |
| 363 | |
| 364 | @event.listens_for(metadata, "column_reflect") |
| 365 | def receive_column_reflect(inspector, table, column_info): |
| 366 | # receives for all Table objects that are reflected |
| 367 | # under this MetaData |
| 368 | ... |
| 369 | |
| 370 | |
| 371 | # will use the above event hook |
| 372 | my_table = Table("my_table", metadata, autoload_with=some_engine) |
| 373 | |
| 374 | .. versionadded:: 1.4.0b2 The :meth:`_events.DDLEvents.column_reflect` |
| 375 | hook may now be applied to a :class:`_schema.MetaData` object as |
| 376 | well as the :class:`_schema.MetaData` class itself where it will |
| 377 | take place for all :class:`_schema.Table` objects associated with |
| 378 | the targeted :class:`_schema.MetaData`. |
| 379 | |
| 380 | It may also be applied to the :class:`_schema.Table` class across |
| 381 | the board:: |
| 382 | |
| 383 | from sqlalchemy import Table |
| 384 | |
| 385 | |
| 386 | @event.listens_for(Table, "column_reflect") |
| 387 | def receive_column_reflect(inspector, table, column_info): |
| 388 | # receives for all Table objects that are reflected |
| 389 | ... |
| 390 | |
| 391 | It can also be applied to a specific :class:`_schema.Table` at the |
| 392 | point that one is being reflected using the |
| 393 | :paramref:`_schema.Table.listeners` parameter:: |
| 394 | |
| 395 | t1 = Table( |
| 396 | "my_table", |
| 397 | autoload_with=some_engine, |
| 398 | listeners=[("column_reflect", receive_column_reflect)], |
| 399 | ) |
| 400 | |
| 401 | The dictionary of column information as returned by the |
| 402 | dialect is passed, and can be modified. The dictionary |
| 403 | is that returned in each element of the list returned |
| 404 | by :meth:`.reflection.Inspector.get_columns`: |
| 405 | |
| 406 | * ``name`` - the column's name, is applied to the |
| 407 | :paramref:`_schema.Column.name` parameter |