Databases¶
Databases.
-
class
sheraf.databases.Database(uri=None, storage=None, nestable=False, db_args=None)¶ Bases:
objectA ZODB
ZODB.DBwrapper with aZODB.interfaces.IStoragefactory.The storage factory will either create a
ZEO.ClientStorage.ClientStorage, aZODB.FileStorage.FileStorage.FileStorage, aZODB.DemoStorage.DemoStorage, 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.
-
close()¶ Closes the database.
-
connection(commit=False, cache_minimize=False, _trackeback_shift=0)¶ 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.
>>> database = sheraf.Database() >>> with database.connection() as connection: ... sheraf.Database.current_connection() is connection True
-
connection_close(connection=None)¶ 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()¶ 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)¶ - Parameters
database_name – The name of the queried database.
- Returns
The database object if it exists. A
KeyErroris raised elsewise.
-
classmethod
get_or_create(**kwargs)¶ - Returns
The database object if it exists. If the database does not exist, it is created with the kwargs arguments.
-
reset(storage=None, uri=None)¶ Close and reopen a database connection.