baseplate.context.sqlalchemy
¶
Configuration Parsing¶
-
sqlalchemy.
engine_from_config
(configuration, prefix='sqlalchemy.', **kwargs)¶ Make an engine from a configuration dictionary.
The keys useful to
engine_from_config()
should be prefixed, e.g.sqlalchemy.url
etc. Theprefix
argument specifies the prefix used to filter keys. Each key is mapped to a corresponding keyword argument oncreate_engine()
. Any keyword arguments given to this function will be passed through. Keyword arguments take precedence over the configuration file.
Classes¶
-
class
baseplate.context.sqlalchemy.
SQLAlchemyEngineContextFactory
(engine)¶ SQLAlchemy core engine context factory.
This factory will attach a SQLAlchemy
sqlalchemy.engine.Engine
to an attribute on the context object. All cursor (query) execution will automatically record diagnostic information.Additionally, the trace and span ID will be added as a comment to the text of the SQL statement. This is to aid correlation of queries with requests.
See also
The engine is the low-level SQLAlchemy API. If you want to use the ORM, consider using
SQLAlchemySessionContextFactory
instead.Parameters: engine (sqlalchemy.engine.Engine) – A configured SQLAlchemy engine.
-
class
baseplate.context.sqlalchemy.
SQLAlchemySessionContextFactory
(engine)¶ SQLAlchemy ORM session context factory.
This factory will attach a new SQLAlchemy
sqlalchemy.orm.session.Session
to an attribute on the context object. All cursor (query) execution will automatically record diagnostic information.The session will be automatically closed, but not committed or rolled back, at the end of each request.
See also
The session is part of the high-level SQLAlchemy ORM API. If you want to do raw queries, consider using
SQLAlchemyEngineContextFactory
instead.Parameters: engine (sqlalchemy.engine.Engine) – A configured SQLAlchemy engine.