oslo_db.sqlalchemy.enginefacade
Module¶oslo_db.sqlalchemy.enginefacade.
LegacyEngineFacade
(sql_connection, slave_connection=None, sqlite_fk=False, autocommit=True, expire_on_commit=False, _conf=None, _factory=None, **kwargs)¶Bases: object
A helper class for removing of global engine instances from oslo.db.
Deprecated since version 1.12.0: Please use oslo_db.sqlalchemy.enginefacade
for new development.
As a library, oslo.db can’t decide where to store/when to create engine and sessionmaker instances, so this must be left for a target application.
On the other hand, in order to simplify the adoption of oslo.db changes, we’ll provide a helper class, which creates engine and sessionmaker on its instantiation and provides get_engine()/get_session() methods that are compatible with corresponding utility functions that currently exist in target projects, e.g. in Nova.
engine/sessionmaker instances will still be global (and they are meant to be global), but they will be stored in the app context, rather that in the oslo.db context.
Two important things to remember:
Parameters: |
|
---|
Keyword arguments:
Parameters: |
|
---|
from_config
(conf, sqlite_fk=False, autocommit=True, expire_on_commit=False)¶Initialize EngineFacade using oslo.config config instance options.
Parameters: |
|
---|
get_engine
(use_slave=False)¶Get the engine instance (note, that it’s shared).
Parameters: | use_slave (bool) – if possible, use ‘slave’ database for this engine. If the connection string for the slave database wasn’t provided, ‘master’ engine will be returned. (defaults to False) |
---|
get_session
(use_slave=False, **kwargs)¶Get a Session instance.
Parameters: | use_slave (bool) – if possible, use ‘slave’ database connection for this session. If the connection string for the slave database wasn’t provided, a session bound to the ‘master’ engine will be returned. (defaults to False) |
---|
Keyword arguments will be passed to a sessionmaker instance as is (if passed, they will override the ones used when the sessionmaker instance was created). See SQLAlchemy Session docs for details.
get_sessionmaker
(use_slave=False)¶Get the sessionmaker instance used to create a Session.
This can be called for those cases where the sessionmaker() is to be temporarily injected with some state such as a specific connection.
oslo_db.sqlalchemy.enginefacade.
configure
(**kw)¶Apply configurational options to the global factory.
This method can only be called before any specific transaction-beginning methods have been called.
See also
_TransactionFactory.configure()
oslo_db.sqlalchemy.enginefacade.
get_legacy_facade
()¶Return a LegacyEngineFacade
for the global factory.
This facade will make use of the same engine and sessionmaker as this factory, however will not share the same transaction context; the legacy facade continues to work the old way of returning a new Session each time get_session() is called.
oslo_db.sqlalchemy.enginefacade.
reader
= <oslo_db.sqlalchemy.enginefacade._TransactionContextManager object>¶The global ‘reader’ starting point.
oslo_db.sqlalchemy.enginefacade.
transaction_context
()¶Construct a local transaction context.
oslo_db.sqlalchemy.enginefacade.
transaction_context_provider
(klass)¶Decorate a class with session
and connection
attributes.
oslo_db.sqlalchemy.enginefacade.
writer
= <oslo_db.sqlalchemy.enginefacade._TransactionContextManager object>¶The global ‘writer’ starting point.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.