Commit a02b68e0 authored by Jim Fulton's avatar Jim Fulton

Enhanced the database opening conveniences:

- You can now pass storage keyword arguments to ZODB.DB and
  ZODB.connection.

- You can now pass None (rather than a storage or file name) to get
  a database with a mapping storage.
parent 193329df
...@@ -24,6 +24,14 @@ New Features ...@@ -24,6 +24,14 @@ New Features
(transaction-manager attempts method) introduced in the (transaction-manager attempts method) introduced in the
``transaction`` 1.1.0 release. ``transaction`` 1.1.0 release.
- Enhanced the database opening conveniences:
- You can now pass storage keyword arguments to ZODB.DB and
ZODB.connection.
- You can now pass None (rather than a storage or file name) to get
a database with a mapping storage.
Bugs Fixed Bugs Fixed
---------- ----------
......
...@@ -386,7 +386,7 @@ class DB(object): ...@@ -386,7 +386,7 @@ class DB(object):
databases=None, databases=None,
xrefs=True, xrefs=True,
max_saved_oids=999, max_saved_oids=999,
): **storage_args):
"""Create an object database. """Create an object database.
:Parameters: :Parameters:
...@@ -409,7 +409,10 @@ class DB(object): ...@@ -409,7 +409,10 @@ class DB(object):
""" """
if isinstance(storage, basestring): if isinstance(storage, basestring):
from ZODB import FileStorage from ZODB import FileStorage
storage = ZODB.FileStorage.FileStorage(storage) storage = ZODB.FileStorage.FileStorage(storage, **storage_args)
elif storage is None:
from ZODB import MappingStorage
storage = ZODB.MappingStorage.MappingStorage(**storage_args)
# Allocate lock. # Allocate lock.
x = threading.RLock() x = threading.RLock()
......
...@@ -161,6 +161,17 @@ def passing_a_file_name_to_DB(): ...@@ -161,6 +161,17 @@ def passing_a_file_name_to_DB():
>>> db.close() >>> db.close()
""" """
def passing_None_to_DB():
"""You can pass None DB to get a MappingStorage.
(Also note that we can access DB in ZODB.)
>>> db = ZODB.DB(None)
>>> db.storage # doctest: +ELLIPSIS
<ZODB.MappingStorage.MappingStorage object at ...
>>> db.close()
"""
def open_convenience(): def open_convenience():
"""Often, we just want to open a single connection. """Often, we just want to open a single connection.
...@@ -180,6 +191,22 @@ def open_convenience(): ...@@ -180,6 +191,22 @@ def open_convenience():
>>> conn.root() >>> conn.root()
{'x': 1} {'x': 1}
>>> db.close() >>> db.close()
We can pass storage-specific arguments if they don't conflict with
DB arguments.
>>> conn = ZODB.connection('data.fs', blob_dir='blobs')
>>> conn.root()['b'] = ZODB.blob.Blob('test')
>>> transaction.commit()
>>> conn.close()
>>> db = ZODB.DB('data.fs', blob_dir='blobs')
>>> conn = db.open()
>>> conn.root()['b'].open().read()
'test'
>>> db.close()
""" """
if sys.version_info >= (2, 6): if sys.version_info >= (2, 6):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment