potoroo package

Python implementations of the Repository and UnitOfWork abstractions.

class BasicRepo[source]

Bases: Generic[K, V], ABC

The simplest possible Repository type.

abstract add(item, /, *, key=None)[source]

Add a new item to the repo and associsate it with key.

Parameters:
  • item (TypeVar(V)) –

  • key (TypeVar(K)) –

Return type:

Union[Ok[TypeVar(K), ErisError], Err[TypeVar(K), ErisError]]

abstract get(key)[source]

Retrieve an item from the repo by key.

Parameters:

key (TypeVar(K)) –

Return type:

Union[Ok[Optional[TypeVar(V)], ErisError], Err[Optional[TypeVar(V)], ErisError]]

class QueryRepo[source]

Bases: Repo[K, V], Generic[K, V, Q], ABC

A Repository that is aware of some kind of “querys”.

Adds the ability to retrieve / delete a group of objects based off of some arbitrary “query” type.

NOTE: In general, K can be expected to be a primitive type, whereas Q is

often a custom user-defined type.

abstract get_by_query(query)[source]

Retrieve a group of items that meet the given query’s criteria.

Parameters:

query (TypeVar(Q)) –

Return type:

Union[Ok[list[TypeVar(V)], ErisError], Err[list[TypeVar(V)], ErisError]]

remove_by_query(query)[source]

Remove a group of items that meet the given query’s criteria.

Parameters:

query (TypeVar(Q)) –

Return type:

Union[Ok[list[TypeVar(V)], ErisError], Err[list[TypeVar(V)], ErisError]]

class Repo[source]

Bases: BasicRepo[K, V], Generic[K, V], ABC

A full-featured Repository

Adds the ability to update, delete, and list all items ontop of the BasicRepo type.

abstract all()[source]

Retrieve all items stored in this repo.

Return type:

Union[Ok[list[TypeVar(V)], ErisError], Err[list[TypeVar(V)], ErisError]]

abstract remove(item, /)[source]

Remove an item from the repo.

Parameters:

item (TypeVar(V)) –

Return type:

Union[Ok[Optional[TypeVar(V)], ErisError], Err[Optional[TypeVar(V)], ErisError]]

remove_by_key(key)[source]

Remove an item from the repo by key.

Parameters:

key (TypeVar(K)) –

Return type:

Union[Ok[Optional[TypeVar(V)], ErisError], Err[Optional[TypeVar(V)], ErisError]]

update(key, item, /)[source]

Update an item by key.

Parameters:
  • key (TypeVar(K)) –

  • item (TypeVar(V)) –

Return type:

Union[Ok[TypeVar(V), ErisError], Err[TypeVar(V), ErisError]]

class UnitOfWork[source]

Bases: Generic[R], ABC

Implements the ‘Unit-of-Work’ persistance pattern.

abstract commit()[source]

Commits our changes to self.repo.

Return type:

None

abstract property repo

The Repo type this UoW is associated with.

abstract rollback()[source]

Reverts our changes to self.repo.

Return type:

None