baseplate.context.sqlalchemy

Configuration Parsing

baseplate.context.sqlalchemy.engine_from_config(app_config, secrets=None, prefix='database.')

Make an Engine from a configuration dictionary.

The keys useful to engine_from_config() should be prefixed, e.g. database.url, etc. The prefix argument specifies the prefix used to filter keys.

Supported keys:

  • url: the connection URL to the database, passed to
    make_url() to create the URL used to connect to the database.
  • credentials_secret (optional): the key used to retrieve the database
    credentials from secrets as a CredentialSecret. If this is supplied, any credentials given in url we be replaced by these.

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.