The seedbox.db.sqlalchemy.session Module

Manages connection to the database via sqlalchemy

class seedbox.db.sqlalchemy.session.EngineFacade(sql_connection, **kwargs)

Bases: object

Helper class that creates engine and sessionmaker.

Performs instantiation and provides get_engine()/get_session() methods.

engine/sessionmaker instances will be global.

Note: Two important things to remember:

  1. An Engine instance is effectively a pool of DB connections, so it’s meant to be shared (and it’s thread-safe).
  2. A Session instance is not meant to be shared and represents a DB transactional context (i.e. it’s not thread-safe). sessionmaker is a factory of sessions.

Initialize engine and sessionmaker instances.

Keyword arguments:

Parameters:
  • idle_timeout – timeout before idle sql connections are reaped (defaults to 3600)
  • connection_debug – verbosity of SQL debugging information. 0=None, 100=Everything (defaults to 0)
engine

Get the engine instance (note, that it’s shared).

classmethod from_config(connection_string, conf)

Initialize EngineFacade using oslo_config config instance options.

Parameters:
  • connection_string (string) – SQLAlchemy connection string
  • conf (oslo_config.cfg.ConfigOpts) – oslo_config config instance
session

Get a Session instance.

session_maker

Get the session maker instance

seedbox.db.sqlalchemy.session.create_engine(sql_connection, idle_timeout=3600, connection_debug=0)

Return a new SQLAlchemy engine.

Parameters:
  • sql_connection – sql connection string
  • idle_timeout – timeout period the connection can be idle
  • connection_debug – enable debugging for the connection
seedbox.db.sqlalchemy.session.get_maker(engine)

Return a SQLAlchemy sessionmaker using the given engine.

Parameters:engine – a database connection engine
seedbox.db.sqlalchemy.session.receive_connect(dbapi_con, con_record)

Ensures that the foreign key constraints are enforced in SQLite.

The foreign key constraints are disabled by default in SQLite, so the foreign key constraints will be enabled here for every database connection

Parameters:
  • dbapi_con – database connection
  • con_record – connection record