Database connection¶
As ZODB databases and storages, sheraf Database
can be configured using a configuration file.
It is done through a zodburi zconfig://
URI scheme.
A simple example ZConfig file:
<zodb>
<mappingstorage>
</mappingstorage>
</zodb>
If that configuration file is located at /etc/myapp/zodb.conf, use the following uri argument to initialize your object:
>>> sheraf.Database("zconfig:///etc/myapp/zodb.conf")
A ZConfig file can specify more than one database. Don’t forget to specify database-name in that case to avoid conflict on name. For instance:
<zodb temp1>
database-name database1
<mappingstorage>
</mappingstorage>
</zodb>
<zodb temp2>
database-name database2
<mappingstorage>
</mappingstorage>
</zodb>
In that case, use a URI with a fragment identifier:
>>> db1 = sheraf.Database("zconfig:///etc/myapp/zodb.conf#temp1")
<Database database1>
>>> db2 = sheraf.Database("zconfig:///etc/myapp/zodb.conf#temp2")
<Database database2>
If not specified in the conf file or in the arguments passed at the initialization of the object, default zodburi values will be used:
database name: unnamed
cache size: 5000
cache size bytes: 0
Note that arguments passed at the initialization of the object override the conf file.