Provides the Session class and related utilities.
Class |
|
Represents a call to the :meth:`_orm.Session.execute` method, as passed to the :meth:`.SessionEvents.do_orm_execute` event hook. |
Class |
|
Manages persistence operations for ORM-mapped objects. |
Class | sessionmaker |
A configurable :class:`.Session` factory. |
Class |
|
A :class:`.Session`-level transaction. |
Class |
|
indicates the origin of a :class:`.SessionTransaction`. |
Class |
|
Undocumented |
Function | close |
Close all sessions in memory. |
Function | make |
Alter the state of the given instance so that it is :term:`transient`. |
Function | make |
Make the given transient instance :term:`detached`. |
Function | object |
Return the :class:`.Session` to which the given instance belongs. |
Constant | ACTIVE |
Undocumented |
Constant | CLOSED |
Undocumented |
Constant | COMMITTED |
Undocumented |
Constant | DEACTIVE |
Undocumented |
Constant | PREPARED |
Undocumented |
Variable |
|
Undocumented |
Class | _ |
a callable that returns a :class:`.Connection` given an instance. |
Class | _ |
Class-level methods for :class:`.Session`, :class:`.sessionmaker`. |
Function | _state |
Given an :class:`.InstanceState`, return the :class:`.Session` associated, if any. |
Type Variable | _S |
Undocumented |
Type Variable | _T |
Undocumented |
Type Alias | _ |
Undocumented |
Type Alias | _ |
Undocumented |
Type Alias | _ |
Undocumented |
Type Alias | _ |
Undocumented |
Type Alias | _ |
Undocumented |
Variable | _new |
Undocumented |
Variable | _sessions |
Weak-referencing dictionary of :class:`.Session` objects. |
Close all sessions in memory. This function consults a global registry of all :class:`.Session` objects and calls :meth:`.Session.close` on them, which resets them to a clean state. This function is not for general use but may be useful for test suites within the teardown scheme. .. versionadded:: 1.3
Alter the state of the given instance so that it is :term:`transient`. .. note:: :func:`.make_transient` is a special-case function for advanced use cases only. The given mapped instance is assumed to be in the :term:`persistent` or :term:`detached` state. The function will remove its association with any :class:`.Session` as well as its :attr:`.InstanceState.identity`. The effect is that the object will behave as though it were newly constructed, except retaining any attribute / collection values that were loaded at the time of the call. The :attr:`.InstanceState.deleted` flag is also reset if this object had been deleted as a result of using :meth:`.Session.delete`. .. warning:: :func:`.make_transient` does **not** "unexpire" or otherwise eagerly load ORM-mapped attributes that are not currently loaded at the time the function is called. This includes attributes which: * were expired via :meth:`.Session.expire` * were expired as the natural effect of committing a session transaction, e.g. :meth:`.Session.commit` * are normally :term:`lazy loaded` but are not currently loaded * are "deferred" (see :ref:`orm_queryguide_column_deferral`) and are not yet loaded * were not present in the query which loaded this object, such as that which is common in joined table inheritance and other scenarios. After :func:`.make_transient` is called, unloaded attributes such as those above will normally resolve to the value ``None`` when accessed, or an empty collection for a collection-oriented attribute. As the object is transient and un-associated with any database identity, it will no longer retrieve these values. .. seealso:: :func:`.make_transient_to_detached`
Make the given transient instance :term:`detached`. .. note:: :func:`.make_transient_to_detached` is a special-case function for advanced use cases only. All attribute history on the given instance will be reset as though the instance were freshly loaded from a query. Missing attributes will be marked as expired. The primary key attributes of the object, which are required, will be made into the "key" of the instance. The object can then be added to a session, or merged possibly with the load=False flag, at which point it will look as if it were loaded that way, without emitting SQL. This is a special use case function that differs from a normal call to :meth:`.Session.merge` in that a given persistent state can be manufactured without any SQL calls. .. seealso:: :func:`.make_transient` :meth:`.Session.enable_relationship_loading`
Return the :class:`.Session` to which the given instance belongs. This is essentially the same as the :attr:`.InstanceState.session` accessor. See that attribute for details.