budosystems.xtra.sqlite3_storage.repository.SQLite3Repository¶
- class SQLite3Repository¶
Bases:
Repository
Implementation of the Repository interface for SQLite3 storage.
- __init__(con: Connection)¶
Abstract initializer that accepts arbitrary keyword arguments.
Implementations should specify more precisely those it needs.
- Parameters:
kwargs – Keyword arguments used for initializing the repository.
- match(entity_type: type[ET], data: dict[str, Any]) list[ET] ¶
An implementation will return every instance of
entity_type
with field values matchingdata
.- Parameters:
entity_type – The specific type of
Entity
expected.data – Mapping where the keys correspond to the field names of the entities, and the values correspond to the field values to match. Omitted keys are not matched.
- load(entity_type: type[ET], entity_id: UUID) ET ¶
Load and return an Entity with an ID matching the parameter.
- Parameters:
entity_type – The specific type of
Entity
expected.entity_id – The ID used to search the repository.
- Returns:
The Entity matching the ID.
- Raises:
EntityNotFound – If there are no entities with the given ID in the repository.
- save(entity: Entity, save_option: SaveOption = SaveOption.create_or_update) None ¶
Store the provided entity.
- Parameters:
entity – The entity object needing to be stored.
save_option – Whether to allow creation, update, or both.
- Raises:
EntityAlreadyExists – If
save_option
is set toSaveOption.create_only
and a matching entity already exists in the repository.EntityNotFound – If
save_option
is set toSaveOption.update_only
and a matching entity does not currently exist in the repository.
- delete(entity_type: type[ET], entity_id: UUID, must_exist: bool = False) None ¶
Delete Entity with an ID matching the parameter.
- Parameters:
entity_type – The specific type of
Entity
expected.entity_id – The ID of the entity to be deleted.
must_exist – If
True
, raises an exception if no entity with the ID exists in the repository. IfFalse
(default), proceed silently.
- Raises:
EntityNotFound – If
must_exist
is set to True and a matching entity does not already exist in the repository.
- find_entities(query: Query) list[Entity] ¶
Search for entities according to the query and return the matching list.
Attention
Not implemented
- Parameters:
query – Specification of the entities to return.
- Returns:
A (possibly empty) list of the entities satisfying the query.
- Raises:
QueryError – If there are problems with the query.
- find_data(query: Query) list[Any] ¶
Search for data according to the query.
Attention
Not implemented
The structure and format of the expected data is specified in the query.
- Parameters:
query – Specification of the data to return.
- Returns:
A (possibly empty) list of the data entries satisfying the query.
- Raises:
QueryError – If there are problems with the query.