KelDB
KelDB
An asynchronous hierarchical key-value database abstraction.
KelDB organizes data as a tree of nodes. Each node can store a value and have subnodes. Storage is delegated to a backend Hook.
- Core Components:
Node: Represents a node in the database tree.
Hook: Backend abstraction interface for custom setups.
FileStoreHook: Filesystem-backed implementation.
KelDB: Root database node.
- class keldb.KelDB(hook: Hook, locks_count: int = 10000)
Bases:
NodeRoot database object.
- async dump_database(target: IO[bytes]) None
Dump the database as a .keldb file.
- Parameters:
target (IO[bytes]) – Binary IO stream to write the database to.
- async get_node_from_path(path: str) Node
Get a reference to a node from a path.
- Parameters:
path (str) – Path of node.
- Returns:
Node reference.
- Return type:
- async load_database_dump(target: IO[bytes]) None
Load a .keldb file into the current database.
- Parameters:
target (IO[bytes]) – Binary IO stream to load the database from
- class keldb.Node
Bases:
objectRepresents a singular node.
This object is a lightweight reference to a database path. It can store a value and contain subnodes.
- name
Node name.
- Type:
str | None
- path
Full database path.
- Type:
str | None
- async delete() None
Recursively delete this node and all subnodes.
- async exists() bool
Check if this node exists.
- Returns:
True if exists.
- Return type:
bool
- async get_lock(area='generic') Lock
- async get_subnode(subnode_name: str) Node
Get a reference to a subnode.
- Parameters:
subnode_name (str) – Name of subnode.
- Returns:
Subnode reference.
- Return type:
- async get_value() Any
Get the value of this node.
- Returns:
Stored value or None.
- Return type:
Any
- async list_subnodes(recursive: bool = False, include_self: bool = False) AsyncIterator[Node]
Iterate over subnodes.
- Parameters:
recursive (bool) – Whether to recursively iterate over the entire tree.
include_self (bool) – Whether to include itself as a node in the list (if the node itself actually exists)
- Yields:
Node – Subnode objects.
- async set_value(value: Any) None
Set the value of this node.
- Parameters:
value (Any) – JSON-serializable value.