common.db_manager¶
-
class
DBManager(db_path)[source]¶ Bases:
objectThe
DBManageris in charge of interacting with a database (LevelDB). Keys and values are stored as bytes in the database but processed as strings by the manager.- Parameters
db_path (
str) – the path (relative or absolute) to the system folder containing the database. A fresh database will be create if the specified path does not contain one.- Raises
ValueError – if the provided
db_pathis not a string.plyvel.Error – if the db is currently unavailable (being used by another process).
-
create_entry(key, value, prefix=None)[source]¶ Creates a new entry in the database.
- Parameters
key (
str) – the key of the new entry, used to identify it.value (
str) – the data stored under the givenkey.prefix (
str) – an optional prefix added to thekey.
- Raises
TypeError – if key, value or prefix are not strings.
-
delete_entry(key, prefix=None)[source]¶ Deletes an entry from the database given an
key(and optionally aprefix).- Parameters
key (
str) – the key that identifies the data to be deleted.prefix (
str) – an optional prefix to be prepended to thekey.
- Raises
TypeError – if key or prefix are not strings.
-
load_entry(key, prefix=None)[source]¶ Loads an entry from the database given a
key(and optionally aprefix).- Parameters
key (
str) – the key that identifies the entry to be loaded.prefix (
str) – an optional prefix added to thekey.
- Returns
A byte-array containing the requested data.
Returns
Noneif the entry is not found.- Return type
bytesorNone- Raises
TypeError – if key or prefix are not strings.