Generalized registry for mapping classes. The :class:`_orm.registry` serves as the basis for maintaining a collection of mappings, and provides configurational hooks used to map classes. The three general kinds of mappings supported are Declarative Base, Declarative Decorator, and
| 1115 | |
| 1116 | |
| 1117 | class registry: |
| 1118 | """Generalized registry for mapping classes. |
| 1119 | |
| 1120 | The :class:`_orm.registry` serves as the basis for maintaining a collection |
| 1121 | of mappings, and provides configurational hooks used to map classes. |
| 1122 | |
| 1123 | The three general kinds of mappings supported are Declarative Base, |
| 1124 | Declarative Decorator, and Imperative Mapping. All of these mapping |
| 1125 | styles may be used interchangeably: |
| 1126 | |
| 1127 | * :meth:`_orm.registry.generate_base` returns a new declarative base |
| 1128 | class, and is the underlying implementation of the |
| 1129 | :func:`_orm.declarative_base` function. |
| 1130 | |
| 1131 | * :meth:`_orm.registry.mapped` provides a class decorator that will |
| 1132 | apply declarative mapping to a class without the use of a declarative |
| 1133 | base class. |
| 1134 | |
| 1135 | * :meth:`_orm.registry.map_imperatively` will produce a |
| 1136 | :class:`_orm.Mapper` for a class without scanning the class for |
| 1137 | declarative class attributes. This method suits the use case historically |
| 1138 | provided by the ``sqlalchemy.orm.mapper()`` classical mapping function, |
| 1139 | which is removed as of SQLAlchemy 2.0. |
| 1140 | |
| 1141 | .. versionadded:: 1.4 |
| 1142 | |
| 1143 | .. seealso:: |
| 1144 | |
| 1145 | :ref:`orm_mapping_classes_toplevel` - overview of class mapping |
| 1146 | styles. |
| 1147 | |
| 1148 | """ |
| 1149 | |
| 1150 | _class_registry: clsregistry._ClsRegistryType |
| 1151 | _managers: weakref.WeakKeyDictionary[ClassManager[Any], Literal[True]] |
| 1152 | _non_primary_mappers: weakref.WeakKeyDictionary[Mapper[Any], Literal[True]] |
| 1153 | metadata: MetaData |
| 1154 | constructor: CallableReference[Callable[..., None]] |
| 1155 | type_annotation_map: _MutableTypeAnnotationMapType |
| 1156 | _dependents: Set[_RegistryType] |
| 1157 | _dependencies: Set[_RegistryType] |
| 1158 | _new_mappers: bool |
| 1159 | |
| 1160 | def __init__( |
| 1161 | self, |
| 1162 | *, |
| 1163 | metadata: Optional[MetaData] = None, |
| 1164 | class_registry: Optional[clsregistry._ClsRegistryType] = None, |
| 1165 | type_annotation_map: Optional[_TypeAnnotationMapType] = None, |
| 1166 | constructor: Callable[..., None] = _declarative_constructor, |
| 1167 | ): |
| 1168 | r"""Construct a new :class:`_orm.registry` |
| 1169 | |
| 1170 | :param metadata: |
| 1171 | An optional :class:`_schema.MetaData` instance. All |
| 1172 | :class:`_schema.Table` objects generated using declarative |
| 1173 | table mapping will make use of this :class:`_schema.MetaData` |
| 1174 | collection. If this argument is left at its default of ``None``, |
no outgoing calls