websauna.system.model.meta module

Database default base models and session setup.

class websauna.system.model.meta.Base(**kwargs)

Bases: object

The most base type

metadata = MetaData(bind=None)
websauna.system.model.meta.create_dbsession(registry, manager=None, *, isolation_level=<object object>)[source]

Creates a new database using the configured session pooling.

This is called outside request life cycle when initializing and checking the state of the databases.

Parameters
  • registry (Registry) – the application registry

  • manager (Optional[TransactionManager]) – Transaction manager to bound the session. The default is thread local transaction.manager.

  • isolation_level – To set a custom isolation level for this session

Return type

Session

websauna.system.model.meta.create_transaction_manager_aware_dbsession(request)[source]

Defaut database factory for Websauna.

Looks up database settings from the INI and creates an SQLALchemy session based on the configuration. The session is terminated on the HTTP request finalizer.

Return type

Session

websauna.system.model.meta.get_default_engine(registry)[source]

Creates or gets the default database engine using the settings in registry.

The engine is a singleton and a reference will be stored in the application registry. :type registry: Registry :param registry: the registry :rtype: Engine :return: the created engine

websauna.system.model.meta.get_engine(settings, prefix='sqlalchemy.')[source]

Reads config and create a database engine out of it.

Parameters
  • settings (dict) – Application settings

  • prefix (str) – Configuration prefixes

Return type

Engine

Returns

SQLAlchemy Engine

websauna.system.model.meta.get_request_tm(request)[source]

Get the underlying transaction manager.

websauna.system.model.meta.includeme(config)[source]

Hook up database initialization and SQLAlchemy global setup.

websauna.system.model.meta.request_session_factory(request)[source]

Look SQLAlchemy session creator.

Return type

Session