Database(uri=None, storage=None, nestable=False, db_args=None)¶
ZODB.DBwrapper with a
The storage factory will either create a
ZODB.DemoStorage.DemoStorage, a Relstorage
PostgreSQLAdapteror use a user defined storage depending on the argument passed at the initialization of the object.
A Storage object is created and pass it to the
Several connections can be used at the same time. The connections are identified by their name.
database_name – The name of the connection.
storage – If set, this user defined storage will be used.
uri (An URI that will be parsed by
zodburi.resolve_uri().) – A zodburi to the database.
db_args – Arguments to pass to the
nestable – If False, will raise a
ConnectionAlreadyOpenedif a connection has already been opened.
Closes the database.
connection(commit=False, cache_minimize=False, _trackeback_shift=0)¶
A context manager opening a connection on this database.
commit (boolean) – Whether to commit the transaction when leaving the context manager.
cache_minimize (boolean) – Whether to call
ZODB.Connection.Connection.cache_minimize()when leaving the context manager.
>>> database = sheraf.Database() >>> with database.connection() as connection: ... sheraf.Database.current_connection() is connection True
Closes a connection opened on the database.
connection – The connection to close, if None the last connection opened on the database is closed.
Opens a connection. Returns a connection to this database.
If nestable is set and a connection has already been opened, raises a
ConnectionAlreadyOpenedexception. If nestable is False and a connection has already been opened, it returns a new connection with a new transaction_manager.
database_name – The name of the queried database.
The database object if it exists. A
KeyErroris raised elsewise.
The database object if it exists. If the database does not exist, it is created with the kwargs arguments.
Close and reopen a database connection.