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
| 1163 | |
| 1164 | |
| 1165 | class registry(EventTarget): |
| 1166 | """Generalized registry for mapping classes. |
| 1167 | |
| 1168 | The :class:`_orm.registry` serves as the basis for maintaining a collection |
| 1169 | of mappings, and provides configurational hooks used to map classes. |
| 1170 | |
| 1171 | The three general kinds of mappings supported are Declarative Base, |
| 1172 | Declarative Decorator, and Imperative Mapping. All of these mapping |
| 1173 | styles may be used interchangeably: |
| 1174 | |
| 1175 | * :meth:`_orm.registry.generate_base` returns a new declarative base |
| 1176 | class, and is the underlying implementation of the |
| 1177 | :func:`_orm.declarative_base` function. |
| 1178 | |
| 1179 | * :meth:`_orm.registry.mapped` provides a class decorator that will |
| 1180 | apply declarative mapping to a class without the use of a declarative |
| 1181 | base class. |
| 1182 | |
| 1183 | * :meth:`_orm.registry.map_imperatively` will produce a |
| 1184 | :class:`_orm.Mapper` for a class without scanning the class for |
| 1185 | declarative class attributes. This method suits the use case historically |
| 1186 | provided by the ``sqlalchemy.orm.mapper()`` classical mapping function, |
| 1187 | which is removed as of SQLAlchemy 2.0. |
| 1188 | |
| 1189 | .. versionadded:: 1.4 |
| 1190 | |
| 1191 | .. seealso:: |
| 1192 | |
| 1193 | :ref:`orm_mapping_classes_toplevel` - overview of class mapping |
| 1194 | styles. |
| 1195 | |
| 1196 | """ |
| 1197 | |
| 1198 | _class_registry: clsregistry._ClsRegistryType |
| 1199 | _managers: weakref.WeakKeyDictionary[ClassManager[Any], Literal[True]] |
| 1200 | metadata: MetaData |
| 1201 | constructor: CallableReference[Callable[..., None]] |
| 1202 | type_annotation_map: _MutableTypeAnnotationMapType |
| 1203 | _dependents: Set[_RegistryType] |
| 1204 | _dependencies: Set[_RegistryType] |
| 1205 | _new_mappers: bool |
| 1206 | dispatch: dispatcher["registry"] |
| 1207 | |
| 1208 | def __init__( |
| 1209 | self, |
| 1210 | *, |
| 1211 | metadata: Optional[MetaData] = None, |
| 1212 | class_registry: Optional[clsregistry._ClsRegistryType] = None, |
| 1213 | type_annotation_map: Optional[_TypeAnnotationMapType] = None, |
| 1214 | constructor: Callable[..., None] = _declarative_constructor, |
| 1215 | ): |
| 1216 | r"""Construct a new :class:`_orm.registry` |
| 1217 | |
| 1218 | :param metadata: |
| 1219 | An optional :class:`_schema.MetaData` instance. All |
| 1220 | :class:`_schema.Table` objects generated using declarative |
| 1221 | table mapping will make use of this :class:`_schema.MetaData` |
| 1222 | collection. If this argument is left at its default of ``None``, |
no outgoing calls