architxt.bucket.zodb#
Classes
|
A persistent, scalable container for |
- class architxt.bucket.zodb.ZODBTreeBucket(storage_path=None, uri=None, bucket_name='architxt', read_only=False)[source]#
Bases:
TreeBucketA persistent, scalable container for
Treeobjects backed by ZODB and RelStorage using SQLite.This container uses ZODB’s
OOBTreeinternally with Tree OIDs (UUIDs) as keys. The OIDs are stored as raw bytes to optimize storage space. This also enables fast key comparisons as UUID objects do not need to be created during lookups.Note
UUIDs are stored as bytes rather than integers, because ZODB only supports integers up to 64 bits, while UUIDs require 128 bits.
If no storage is specified, the bucket use a temporary database that is automatically deleted upon closing.
The bucket is serializable so it can be passed to a subprocess. However, when a temporary database is used, the original bucket remains responsible for cleanup. This means the original bucket must stay open for the subprocess to access the database safely.
>>> from architxt.bucket.zodb import ZODBTreeBucket >>> from architxt.tree import Tree
>>> bucket = ZODBTreeBucket() >>> tree = Tree.fromstring('(S (NP Alice) (VP (VB like) (NNS apples)))') >>> tree.label 'S'
>>> with bucket.transaction(): ... bucket.add(tree) # Add the tree to the bucket >>> len(bucket) 1 >>> tree in bucket True
>>> with bucket.transaction(): ... tree.label = 'ROOT' # Modify the tree within a transaction >>> tree.label 'ROOT' >>> bucket[tree.oid].label 'ROOT'
>>> with bucket.transaction(): ... tree.label = 'S' ... raise ValueError("rollback") # Transaction are rolled back on exception Traceback (most recent call last): ... ValueError: rollback
>>> tree.label 'ROOT' >>> with bucket.transaction(): ... bucket.discard(tree) >>> len(bucket) 0 >>> tree in bucket False
>>> bucket.close()
- close()[source]#
Close the database connection and release associated resources.
This will: - Abort any uncommitted transaction. - Close the active database connection. - Clean up temporary storage if one was created.
- Return type:
- oids()[source]#
Yield the object IDs (OIDs) of all trees stored in the bucket.
- Return type:
Generator[TreeOID, None, None]