module documentation

Undocumented

Class AliasedClass Represents an "aliased" form of a mapped class for usage with Query.
Class AliasedInsp Provide an inspection interface for an :class:`.AliasedClass` object.
Class Bundle A grouping of SQL expressions that are returned by a :class:`.Query` under one namespace.
Class CascadeOptions Keeps track of the options sent to :paramref:`.relationship.cascade`
Class LoaderCriteriaOption Add additional WHERE criteria to the load for all occurrences of a particular entity.
Class ORMAdapter ColumnAdapter subclass which excludes adaptation of entities from non-matching mappers.
Class ORMStatementAdapter ColumnAdapter which includes a role attribute.
Function has_identity Return True if the given object has a database identity.
Function identity_key Generate "identity key" tuples, as are used as keys in the :attr:`.Session.identity_map` dictionary.
Function polymorphic_union Create a ``UNION`` statement used by a polymorphic mapper.
Function was_deleted Return True if the given object was deleted within a session flush.
Function with_parent Create filtering criterion that relates this query's primary entity to the given related instance, using established :func:`_orm.relationship()` configuration.
Variable all_cascades Undocumented
Variable de_stringify_annotation Undocumented
Variable de_stringify_union_elements Undocumented
Variable eval_name_only Undocumented
Variable GenericAlias Undocumented
Class _DeStringifyAnnotation Undocumented
Class _DeStringifyUnionElements Undocumented
Class _EvalNameOnly Undocumented
Class _ORMJoin Extend Join to support ORM constructs as input.
Class _TraceAdaptRole Enumeration of all the use cases for ORMAdapter.
Class _WrapUserEntity A wrapper used within the loader_criteria lambda caller so that we can bypass declared_attr descriptors on unmapped mixins, which normally emit a warning for such use.
Exception _CleanupError Undocumented
Function _cleanup_mapped_str_annotation Undocumented
Function _entity_corresponds_to determine if 'given' corresponds to 'entity', in terms of an entity passed to Query that would match the same entity being referred to elsewhere in the query.
Function _entity_corresponds_to_use_path_impl determine if 'given' corresponds to 'entity', in terms of a path of loader options where a mapped attribute is taken to be a member of a parent entity.
Function _entity_isa determine if 'given' "is a" mapper, in terms of the given would load rows of type 'mapper'.
Function _extract_mapped_subtype given an annotation, figure out if it's ``Mapped[something]`` and if so, return the ``something`` part.
Function _getitem calculate __getitem__ in terms of an iterable query object that also has a slice() method.
Function _inspect_generic_alias Undocumented
Function _inspect_mc Undocumented
Function _is_mapped_annotation Undocumented
Function _orm_annotate Deep copy the given ClauseElement, annotating each element with the "_orm_adapt" flag.
Function _orm_deannotate Remove annotations that link a column to a particular mapping.
Function _orm_full_deannotate Undocumented
Function _validator_events Runs a validation method on an attribute value to be set or appended.
Type Variable _T Undocumented
Variable _de_stringify_partial Undocumented
def has_identity(object_: object) -> bool: (source)

Return True if the given object has a database identity. This typically corresponds to the object being in either the persistent or detached state. .. seealso:: :func:`.was_deleted`

def identity_key(class_: Optional[Type[_T]] = None, ident: Union[Any, Tuple[Any, ...]] = None, *, instance: Optional[_T] = None, row: Optional[Union[Row[Any], RowMapping]] = None, identity_token: Optional[Any] = None) -> _IdentityKeyType[_T]: (source)

Generate "identity key" tuples, as are used as keys in the :attr:`.Session.identity_map` dictionary. This function has several call styles: * ``identity_key(class, ident, identity_token=token)`` This form receives a mapped class and a primary key scalar or tuple as an argument. E.g.:: >>> identity_key(MyClass, (1, 2)) (<class '__main__.MyClass'>, (1, 2), None) :param class: mapped class (must be a positional argument) :param ident: primary key, may be a scalar or tuple argument. :param identity_token: optional identity token .. versionadded:: 1.2 added identity_token * ``identity_key(instance=instance)`` This form will produce the identity key for a given instance. The instance need not be persistent, only that its primary key attributes are populated (else the key will contain ``None`` for those missing values). E.g.:: >>> instance = MyClass(1, 2) >>> identity_key(instance=instance) (<class '__main__.MyClass'>, (1, 2), None) In this form, the given instance is ultimately run though :meth:`_orm.Mapper.identity_key_from_instance`, which will have the effect of performing a database check for the corresponding row if the object is expired. :param instance: object instance (must be given as a keyword arg) * ``identity_key(class, row=row, identity_token=token)`` This form is similar to the class/tuple form, except is passed a database result row as a :class:`.Row` or :class:`.RowMapping` object. E.g.:: >>> row = engine.execute(\ text("select * from table where a=1 and b=2")\ ).first() >>> identity_key(MyClass, row=row) (<class '__main__.MyClass'>, (1, 2), None) :param class: mapped class (must be a positional argument) :param row: :class:`.Row` row returned by a :class:`_engine.CursorResult` (must be given as a keyword arg) :param identity_token: optional identity token .. versionadded:: 1.2 added identity_token

def polymorphic_union(table_map, typecolname, aliasname='p_union', cast_nulls=True): (source)

Create a ``UNION`` statement used by a polymorphic mapper. See :ref:`concrete_inheritance` for an example of how this is used. :param table_map: mapping of polymorphic identities to :class:`_schema.Table` objects. :param typecolname: string name of a "discriminator" column, which will be derived from the query, producing the polymorphic identity for each row. If ``None``, no polymorphic discriminator is generated. :param aliasname: name of the :func:`~sqlalchemy.sql.expression.alias()` construct generated. :param cast_nulls: if True, non-existent columns, which are represented as labeled NULLs, will be passed into CAST. This is a legacy behavior that is problematic on some backends such as Oracle - in which case it can be set to False.

def was_deleted(object_: object) -> bool: (source)

Return True if the given object was deleted within a session flush. This is regardless of whether or not the object is persistent or detached. .. seealso:: :attr:`.InstanceState.was_deleted`

def with_parent(instance: object, prop: attributes.QueryableAttribute[Any], from_entity: Optional[_EntityType[Any]] = None) -> ColumnElement[bool]: (source)

Create filtering criterion that relates this query's primary entity to the given related instance, using established :func:`_orm.relationship()` configuration. E.g.:: stmt = select(Address).where(with_parent(some_user, User.addresses)) The SQL rendered is the same as that rendered when a lazy loader would fire off from the given parent on that attribute, meaning that the appropriate state is taken from the parent object in Python without the need to render joins to the parent table in the rendered statement. The given property may also make use of :meth:`_orm.PropComparator.of_type` to indicate the left side of the criteria:: a1 = aliased(Address) a2 = aliased(Address) stmt = select(a1, a2).where( with_parent(u1, User.addresses.of_type(a2)) ) The above use is equivalent to using the :func:`_orm.with_parent.from_entity` argument:: a1 = aliased(Address) a2 = aliased(Address) stmt = select(a1, a2).where( with_parent(u1, User.addresses, from_entity=a2) ) :param instance: An instance which has some :func:`_orm.relationship`. :param property: Class-bound attribute, which indicates what relationship from the instance should be used to reconcile the parent/child relationship. :param from_entity: Entity in which to consider as the left side. This defaults to the "zero" entity of the :class:`_query.Query` itself. .. versionadded:: 1.2

all_cascades = (source)

Undocumented

de_stringify_annotation = (source)

Undocumented

de_stringify_union_elements = (source)

Undocumented

eval_name_only = (source)

Undocumented

GenericAlias = (source)

Undocumented

def _cleanup_mapped_str_annotation(annotation: str, originating_module: str) -> str: (source)

Undocumented

def _entity_corresponds_to(given: _InternalEntityType[Any], entity: _InternalEntityType[Any]) -> bool: (source)

determine if 'given' corresponds to 'entity', in terms of an entity passed to Query that would match the same entity being referred to elsewhere in the query.

def _entity_corresponds_to_use_path_impl(given: _InternalEntityType[Any], entity: _InternalEntityType[Any]) -> bool: (source)

determine if 'given' corresponds to 'entity', in terms of a path of loader options where a mapped attribute is taken to be a member of a parent entity. e.g.:: someoption(A).someoption(A.b) # -> fn(A, A) -> True someoption(A).someoption(C.d) # -> fn(A, C) -> False a1 = aliased(A) someoption(a1).someoption(A.b) # -> fn(a1, A) -> False someoption(a1).someoption(a1.b) # -> fn(a1, a1) -> True wp = with_polymorphic(A, [A1, A2]) someoption(wp).someoption(A1.foo) # -> fn(wp, A1) -> False someoption(wp).someoption(wp.A1.foo) # -> fn(wp, wp.A1) -> True

def _entity_isa(given: _InternalEntityType[Any], mapper: Mapper[Any]) -> bool: (source)

determine if 'given' "is a" mapper, in terms of the given would load rows of type 'mapper'.

def _extract_mapped_subtype(raw_annotation: Optional[_AnnotationScanType], cls: type, originating_module: str, key: str, attr_cls: Type[Any], required: bool, is_dataclass_field: bool, expect_mapped: bool = True, raiseerr: bool = True) -> Optional[Tuple[Union[type, str], Optional[type]]]: (source)

given an annotation, figure out if it's ``Mapped[something]`` and if so, return the ``something`` part. Includes error raise scenarios and other options.

def _getitem(iterable_query: Query[Any], item: Any) -> Any: (source)

calculate __getitem__ in terms of an iterable query object that also has a slice() method.

@inspection._inspects(GenericAlias)
def _inspect_generic_alias(class_: Type[_O]) -> Optional[Mapper[_O]]: (source)

Undocumented

@inspection._inspects(type)
def _inspect_mc(class_: Type[_O]) -> Optional[Mapper[_O]]: (source)

Undocumented

def _is_mapped_annotation(raw_annotation: _AnnotationScanType, cls: Type[Any], originating_cls: Type[Any]) -> bool: (source)

Undocumented

def _orm_annotate(element: _SA, exclude: Optional[Any] = None) -> _SA: (source)

Deep copy the given ClauseElement, annotating each element with the "_orm_adapt" flag. Elements within the exclude collection will be cloned but not annotated.

def _orm_deannotate(element: _SA) -> _SA: (source)

Remove annotations that link a column to a particular mapping. Note this doesn't affect "remote" and "foreign" annotations passed by the :func:`_orm.foreign` and :func:`_orm.remote` annotators.

def _orm_full_deannotate(element: _SA) -> _SA: (source)

Undocumented

def _validator_events(desc, key, validator, include_removes, include_backrefs): (source)

Runs a validation method on an attribute value to be set or appended.

Undocumented

Value
TypeVar('_T',
        bound=Any)
_de_stringify_partial = (source)

Undocumented