data.storage.storage
EntityType
pylint: disable=invalid-name
EntityKeyType
pylint: disable=invalid-name
Storage Objects
class Storage(typing.Generic[EntityType, EntityKeyType], abc.ABC)
Defines a general storage interface for basic CRUD operations.
next_id
@abc.abstractmethod
def next_id() -> EntityKeyType
Gets the next ID to use for a new entity.
add
@abc.abstractmethod
def add(entity: EntityType) -> None
Adds a new entity or updates an existing one.
Raises:
StorageException- If the entity couldn't be added.
remove
@abc.abstractmethod
def remove(entity: EntityType) -> None
Removes an entity.
Raises:
StorageException- If the entity couldn't be removed.
get
@abc.abstractmethod
def get(key: EntityKeyType) -> EntityType | None
Retrieves the entity identified by the given key.
Returns:
The found entity, or None if no entity with the given key exists.
Raises:
StorageException- If the entity couldn't be fetched (not due to a missing key).
list
@abc.abstractmethod
def list() -> typing.List[EntityType]
Retrieves all stored entities.
Returns:
A list of all entitites.
Raises:
StorageException- If the entities couldn't be listed.