abc
AbstractRepository defines the interface for interacting with the application persistent data.
AbstractRepository ¶
Bases: Generic[T]
Defines the interface for interacting with the application persistent data.
id_attribute
class-attribute
¶
Name of the primary identifying attribute on model_type.
add
async
abstractmethod
¶
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
¶
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 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 |
get
async
abstractmethod
¶
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 |
get_id_attribute_value
classmethod
¶
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 |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value of attribute on |
list
async
abstractmethod
¶
set_id_attribute_value
classmethod
¶
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 |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Item with |
update
async
abstractmethod
¶
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 |
required |
Returns:
| Type | Description |
|---|---|
T
|
The updated instance. |
Raises:
| Type | Description |
|---|---|
RepositoryNotFoundException
|
If no instance found with same identifier as |
upsert
async
abstractmethod
¶
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 |
required |
Returns:
| Type | Description |
|---|---|
T
|
The updated or created instance. |
Raises:
| Type | Description |
|---|---|
RepositoryNotFoundException
|
If no instance found with same identifier as |