abc
Data persistence interface.
AbstractRepository ¶
Bases: Generic[T]
Interface for persistent data interaction.
id_attribute
class-attribute
¶
Name of the primary identifying attribute on model_type
.
add
abstractmethod
async
¶
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
abstractmethod
async
¶
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 |
filter_collection_by_kwargs
abstractmethod
¶
Filter the collection by kwargs.
Has AND
semantics where multiple kwargs name/value pairs are provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
Any
|
key/value pairs such that objects remaining in the collection after filtering
have the property that their attribute named |
{}
|
Raises:
Type | Description |
---|---|
RepositoryException
|
if a named attribute doesn't exist on |
get
abstractmethod
async
¶
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
¶
Get 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
abstractmethod
async
¶
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
¶
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
abstractmethod
async
¶
Update 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
abstractmethod
async
¶
Update or create instance.
Updates instance with the attribute values present on data
, or creates 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 |