- class falcon_sqla.Manager(engine, session_cls=<class 'falcon_sqla.session.RequestSession'>, binds=None)
A manager for SQLAlchemy sessions.
This manager allows registering multiple SQLAlchemy engines, specifying if they are read-write or read-only or write-only capable.
engine (Engine) – An instance of a SQLAlchemy Engine, usually obtained with its
create_enginefunction. This engine is added as read-write.
session_cls (type, optional) – Session class used by this engine to create the session. Should be a subclass of SQLAlchemy
Sessionclass. Defaults to
binds (dict, optional) – A dictionary that allows specifying custom binds on a per-entity basis in the session. See also https://docs.sqlalchemy.org/en/13/orm/session_api.html#sqlalchemy.orm.session.Session.params.binds. Defaults to
- add_engine(engine, role=EngineRole.READ)
Adds a new engine with the specified role.
engine (Engine) – An instance of a SQLAlchemy Engine.
role (EngineRole) –
The role of the provided engine. Defaults to
In early versions of this library, role used to take string values:
'rw'. These values will continue to be supported in the foreseeable future for backwards compatibility, but new code should prefer passing enum constants instead.
- close_session(session, succeeded, req=None, resp=None)
Close a session obtained via
There is no need to invoke this method manually if you are using the
session_scope()context manager, or if you are using middleware.
- get_bind(req, resp, session, mapper, clause)
Choose the appropriate bind for the given request session.
This method is not used directly, it’s called by the session instance if multiple engines are defined.
- get_session(req=None, resp=None)
Returns a new session object.
- property read_engines
A tuple of read capable engines.
- session_scope(req=None, resp=None)
Provide a transactional scope around a series of operations.
The session is obtained via
get_sesion(), and finalized using
close_session()upon exiting the context manager.
Based on the
session_scope()recipe from https://docs.sqlalchemy.org/orm/session_basics.html.
- property write_engines
A tuple of write capable engines.