Skip to content

abc

AbstractRepository defines the interface for interacting with the application persistent data.

AbstractRepository

AbstractRepository(session)

Bases: Generic[T]

Defines the interface for interacting with the application persistent data.

id_attribute class-attribute

id_attribute = 'id'

Name of the primary identifying attribute on model_type.

model_type class-attribute

model_type: type[T]

Type of object represented by the repository.

add async abstractmethod

add(data)

Add data to the collection.

Parameters:

Name Type Description Default
data T

Instance to be added to the collection.

required

Returns:

Type Description
T

The added instance.

check_not_found staticmethod

check_not_found(item_or_none)

Raise RepositoryNotFoundException if item_or_none is None.

Parameters:

Name Type Description Default
item_or_none T | None

Item to be tested for existence.

required

Returns:

Type Description
T

The item, if it exists.

delete async abstractmethod

delete(id_)

Delete instance identified by id_

Parameters:

Name Type Description Default
id_ Any

Identifier of instance to be deleted.

required

Returns:

Type Description
T

The deleted instance.

Raises:

Type Description
RepositoryNotFoundException

If no instance found identified by id_.

get async abstractmethod

get(id_)

Get instance identified by id_.

Parameters:

Name Type Description Default
id_ Any

Identifier of the instance to be retrieved.

required

Returns:

Type Description
T

The retrieved instance.

Raises:

Type Description
RepositoryNotFoundException

If no instance found identified by id_.

get_id_attribute_value classmethod

get_id_attribute_value(item)

Return the value of attribute named as self.id_attribute on item.

Parameters:

Name Type Description Default
item T

Anything that should have an attribute named as self.id_attribute value.

required

Returns:

Type Description
Any

The value of attribute on item named as self.id_attribute.

list async abstractmethod

list(*filters, **kwargs)

Get a list of instances, optionally filtered.

Parameters:

Name Type Description Default
*filters FilterTypes

Types for specific filtering operations.

()
**kwargs Any

Instance attribute value filters.

{}

Returns:

Type Description
list[T]

The list of instances, after filtering applied.

set_id_attribute_value classmethod

set_id_attribute_value(id_, item)

Return the item after the ID is set to the appropriate attribute.

Parameters:

Name Type Description Default
id_ Any

Value of ID to be set on instance

required
item T

Anything that should have an attribute named as self.id_attribute value.

required

Returns:

Type Description
Any

Item with id_ set to cls.id_attribute

update async abstractmethod

update(data)

Update an existing instance with the attribute values present on data.

Parameters:

Name Type Description Default
data T

An instance that should have a value for self.id_attribute that exists in the collection.

required

Returns:

Type Description
T

The updated instance.

Raises:

Type Description
RepositoryNotFoundException

If no instance found with same identifier as data.

upsert async abstractmethod

upsert(data)

Update an existing instance with the attribute values present on data, or create a new instance if one doesn't exist.

Parameters:

Name Type Description Default
data T

Instance to update existing, or be created. Identifier used to determine if an existing instance exists is the value of an attribute on data named as value of self.id_attribute.

required

Returns:

Type Description
T

The updated or created instance.

Raises:

Type Description
RepositoryNotFoundException

If no instance found with same identifier as data.