repository¶
Repository base class for creating system-agnostic object storage.
-
exception
frequent.repository.
ObjectNotFoundError
(id: Any, field: str = 'id')[source]¶ Bases:
frequent.repository.RepositoryException
Exception thrown when an object could not be found.
- Parameters
id (object) – The identifier for which no object could be found.
field (str) – The lookup field, which for the value id, no object could be found.
-
class
frequent.repository.
Repository
[source]¶ Bases:
abc.ABC
Base class for creating object repositories.
-
abstract
add
(obj: Any) → None[source]¶ Adds an object to this storage repository.
- Parameters
obj (object) – The object to add to this storage repository.
-
abstract
all
() → Iterable[Any][source]¶ All the objects stored in this repository.
- Returns
An iterable object of all the objects contained in this repository.
- Return type
Iterable
ofobject
Note
If you don’t want your implementation to have the ability to return all of the objects simply have your implementation either return an empty container (e.g. return []) or (more pythonically) raise a
NotImplementedError
.
-
get
(id: Any) → Any[source]¶ Gets an object from this storage repository.
- Parameters
id (object) – The identifier to use to get the associated object for.
- Returns
The object associated with the given id.
- Return type
object
- Raises
ObjectNotFoundError – If no object was found for the given id.
-
abstract
remove
(id: Any) → Any[source]¶ Removes and returns an object from this repository.
- Parameters
id (object) – The identifier to remove the associated object for.
- Returns
The object removed from this repository.
- Return type
object
- Raises
ObjectNotFoundError – If no object was found for the given id.
Note
If you don’t want your implementation to have the ability to remove objects simply have your implementation either return
None
or (more pythonically) raise aNotImplementedError
.
-
abstract