Databases
- class sheraf.databases.Database(uri=None, storage=None, nestable=False, db_args=None)[source]
Bases:
objectA ZODB
ZODB.DBwrapper with aZODB.interfaces.IStoragefactory.The storage factory will either create a
ClientStorage, aFileStorage, aDemoStorage, a RelstoragePostgreSQLAdapteror 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
ZODB.DBconstructorSeveral connections can be used at the same time. The connections are identified by their name.
- Parameters:
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
ZODB.DB.nestable – If False, will raise a
ConnectionAlreadyOpenedif a connection has already been opened.
- classmethod all()[source]
- Returns:
A list containing all the existing
Databasein a tuple (name, Database).
- connection(commit=False, cache_minimize=False, reuse=False, _trackeback_shift=0)[source]
A context manager opening a connection on this database.
- Parameters:
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.reuse (boolean) – If a connection is already opened, reuse it.
>>> database = sheraf.Database() >>> with database.connection() as connection: ... sheraf.Database.current_connection() is connection True
- connection_close(connection=None)[source]
Closes a connection opened on the database.
- Parameters:
connection – The connection to close, if None the last connection opened on the database is closed.
- connection_open()[source]
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.- Returns:
A
Connectionobject.
- classmethod get(database_name=None)[source]
- Parameters:
database_name – The name of the queried database.
- Returns:
The database object if it exists. A
KeyErroris raised elsewise.
- sheraf.databases.connection(database_name=None, commit=False, cache_minimize=False, reuse=False)[source]
Shortcut for
sheraf.databases.Database.connection()- Parameters:
database_name – The name of the database on which to open a connection. If not set, the default database will be used.
*kwargs –
See
sheraf.databases.Database.connection()arguments.