common.db_manager

class DBManager(db_path)[source]

Bases: object

The DBManager is 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_path is 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 given key.

  • prefix (str) – an optional prefix added to the key.

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 a prefix).

Parameters
  • key (str) – the key that identifies the data to be deleted.

  • prefix (str) – an optional prefix to be prepended to the key.

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 a prefix).

Parameters
  • key (str) – the key that identifies the entry to be loaded.

  • prefix (str) – an optional prefix added to the key.

Returns

A byte-array containing the requested data.

Returns None if the entry is not found.

Return type

bytes or None

Raises

TypeError – if key or prefix are not strings.