py4ai.data.layer.fs.repository module
Module for Repository pattern for FileSystem persistence layers.
- class py4ai.data.layer.fs.repository.FileSystemRepository(path: Path, serializer: FileSerializer[KE, E])
Bases:
Repository
[KE
,str
,E
,IndexedIO
[KE
],List
[KE
]],Generic
[KE
,E
]Class implementing MongoDB repository.
Return a FileSystem Repository Implementation.
The current implementation uses the Motor async framework.
- Parameters
path – location where objects are stored
serializer – Serializer to be used to serialize/deserialize FileSystem raw objects into domain objects
- async create(entity: E) E
Create the entity in the underlying persistence layer.
- Parameters
entity – Entity to be created
- Returns
same entity provided as input, after creation. If creation fails, an error should be returned.
- criteria: FileSystemCriteriaFactory[KE, E]
- async delete(key: KE) bool
Delete the entry in the persisence layer associated to the provided entity key.
- Parameters
key – key identifying the entity.
- Returns
boolean value indicating whether the deletion has completed successfully.
- async delete_by_criteria(criteria: SearchCriteria[List[KE]]) bool
Delete all entries matching a given query.
- Parameters
criteria – query to be used for deleting entries.
- Returns
boolean value indicating whether the deletion has completed successfully.
- async list(options: ~py4ai.data.layer.common.repository.QueryOptions = <py4ai.data.layer.common.repository.QueryOptions object>) Paged[E]
Return a full list of entities stored in the persistence layer.
- Parameters
options – query options to be used when retrieving data
- Returns
Paged object for retrieved list of entities
- async retrieve(key: KE) Optional[E]
Return an entry corresponding to a determined Entity key. If no match is found, returns None.
- Parameters
key – Entity Key to be used for retrieving the entity.
- Returns
Entity associated with the provided key. If no match is found, None is returned.
- async retrieve_by_criteria(criteria: ~py4ai.data.layer.common.criteria.SearchCriteria[~typing.List[~py4ai.core.types.KE]], options: ~py4ai.data.layer.common.repository.QueryOptions = <py4ai.data.layer.common.repository.QueryOptions object>) Paged[E]
Return a list of entities, matching the query provided.
- Parameters
criteria – query to be used for selecting items
options – query options to be used when retrieving data
- Returns
Paged object for retrieved list of entities
- Raises
ValueError – when multiple sorting options are provided. Note that FileSystem repositories only support one sorting option.
- async save(entities: Sequence[E]) Sequence[E]
Create the entries in the persistence layer associated to a list of entities.
- Parameters
entities – list of entities to be created.
- Returns
list of entities that have been successfully created in the persistence layer
- property serializer: FileSerializer[KE, E]
Return the serializer.
- Returns
DataSerializer for serializing/deserializing FileSystem documents into domain objects