Session Manager¶
- 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.
- Parameters:
engine (Engine) – An instance of a SQLAlchemy Engine, usually obtained with its
create_engine
function. 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
Session
class. Defaults toRequestSession
.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
None
.
- add_engine(engine, role='r')¶
Adds a new engine with the specified role.
- Parameters:
engine (Engine) – An instance of a SQLAlchemy Engine.
role ({'r', 'rw', 'w'}, optional) – The role of the engine (‘r’: read-ony, ‘rw’: read-write, ‘w’: write-only). Defaults to ‘r’.
- 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 middleware¶
Create a new
Middleware
instance connected to this manager.
- property read_engines¶
A tuple of read capable engines.
- session_scope(req=None, resp=None)¶
Provide a transactional scope around a series of operations.
Based on the
session_scope()
recipe from https://docs.sqlalchemy.org/orm/session_basics.html.
- property write_engines¶
A tuple of write capable engines.