class documentation

class scoped_session(ScopedSessionMixin):

View In Hierarchy

Provides scoped management of .Session objects.

See :ref:`unitofwork_contextual` for a tutorial.

Note

When using :ref:`asyncio_toplevel`, the async-compatible _asyncio.async_scoped_session class should be used in place of .scoped_session.

Method __init__ Construct a new .scoped_session.
Method query​_property return a class property which produces a _query.Query object against the class and the current .Session when called.
Method remove Dispose of the current .Session, if present.
Instance Variable session​_factory No summary
Class Variable ​_support​_async Undocumented
Instance Variable registry Undocumented

Inherited from ScopedSessionMixin:

Method __call__ Return the current .Session, creating it using the .scoped_session.session_factory if not present.
Method configure reconfigure the .sessionmaker used by this .scoped_session.
Property ​_proxied Undocumented
def __init__(self, session_factory, scopefunc=None):
Construct a new .scoped_session.
Parameters
session​_factorya factory to create new .Session instances. This is usually, but not necessarily, an instance of .sessionmaker.
scopefuncoptional function which defines the current scope. If not passed, the .scoped_session object assumes "thread-local" scope, and will use a Python threading.local() in order to maintain the current .Session. If passed, the function should return a hashable token; this token will be used as the key in a dictionary in order to store and retrieve the current .Session.
def query_property(self, query_cls=None):

return a class property which produces a _query.Query object against the class and the current .Session when called.

e.g.:

Session = scoped_session(sessionmaker())

class MyClass(object):
    query = Session.query_property()

# after mappers are defined
result = MyClass.query.filter(MyClass.name=='foo').all()

Produces instances of the session's configured query class by default. To override and use a custom implementation, provide a query_cls callable. The callable will be invoked with the class's mapper as a positional argument and a session keyword argument.

There is no limit to the number of query properties placed on a class.

def remove(self):

Dispose of the current .Session, if present.

This will first call .Session.close method on the current .Session, which releases any existing transactional/connection resources still being held; transactions specifically are rolled back. The .Session is then discarded. Upon next usage within the same scope, the .scoped_session will produce a new .Session object.

session_factory =
The session_factory provided to __init__ is stored in this attribute and may be accessed at a later time. This can be useful when a new non-scoped .Session or _engine.Connection to the database is needed.
_support_async: bool =

Undocumented

registry =

Undocumented