BaseDatabase

class pyrubrum.BaseDatabase

Basic representation of a database, which, by definition, implements the three fundamental operations delete, get and set.

The purpose of this class is to give a general interface for a database, as it does not implement anything.

A sample implementation of this interface is RedisDatabase.

Note

In order to create a subclass or to access this interface, you will need to implement all the abstract methods, which are delete, get and set. Otherwise, you will get an error.

abstract get(key: str)str

This abstract method is intended to be implemented in order to get the value which is stored with a certain key inside the database.

Parameters

key (str) – The key you are retrieving the value of.

Returns

The value which is associated to the key.

Return type

Optional[str]

Raises
  • GetError – If an error occured while retrieving the key from the database.

  • NotFoundError – If the provided key is not found.

abstract set(key: str, value: str, expire: Optional[Union[bool, int, datetime.timedelta]] = None)

This abstract method is intended to be implemented in order to assign a value to a certain key inside the database. It may even be marked with an expire as to avoid having too much unused data stored inside the database.

Parameters
  • key (str) – The key you are adding or updating the value of.

  • value (str) – The value which is being assigned to the key.

  • expire (Optional[Types.Expire]) – The expire in seconds or as a timedelta object. A key is set not to expire if False is provided for this argument. Defaults to None.

Raises
  • ExpireError – If an error occured while setting the expire for the key.

  • SetError – If an error occured while inserting the key into the database.

abstract delete(key: str)

This abstract method is intended to be implemented in order to delete a certain key from the database, together with its stored value.

Parameters

key (str) – The key which is being deleted from the database, together with its linked data.

Raises