py4ai.data.layer.common.repository module
Module containing the abstractions and implementations for repository classes.
- class py4ai.data.layer.common.repository.Paged(size: int, items: List[E], more_pages: bool)
Bases:
Generic
[E
],WithLogging
Class representing a Paged query result.
Instantiate a paged list of elements class.
- Parameters
size – number of results
items – list of returned objects
more_pages – flag to notify whether there are more pages or not
- items: List[E]
- more_pages: bool
- size: int
- class py4ai.data.layer.common.repository.QueryOptions(page_start: int = 0, page_size: int = -1, sorting_options: List[Tuple[str, SortingDirection]] = [])
Bases:
WithLogging
Class for providing query options.
Implement the options to be used in a query call in the repository abstraction.
- Parameters
page_start – integer setting the current page
page_size – integer setting the size of paging (default value is -1 - all result are returned in one page)
sorting_options – a list of options for ordering results
- copy(page_start: Optional[int] = 0, page_size: Optional[int] = -1, sorting_options: Optional[List[Tuple[str, SortingDirection]]] = None) QueryOptions
Copy the object, overriding provided properties.
- Parameters
page_start – integer setting the current page
page_size – integer setting the size of paging (default value is -1 - all result are returned in one page)
sorting_options – a list of options for ordering results
- Returns
new object, with overridden properties.
- class py4ai.data.layer.common.repository.Repository(*args, **kwds)
Bases:
Generic
[KE
,KD
,E
,D
,Q
],WithLogging
,ABC
Abstract class representing the base Repository.
- abstract 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.
- abstract async delete(key: KE) bool
Delete the entry in the persistence layer associated to the provided entity key.
- Parameters
key – key identifying the entity.
- Returns
boolean value indicating whether the deletion has completed successfully.
- abstract async delete_by_criteria(criteria: SearchCriteria[Q]) 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.
- abstract 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.
- abstract async retrieve_by_criteria(criteria: ~py4ai.data.layer.common.criteria.SearchCriteria[~py4ai.core.types.Q], 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
- abstract 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
- abstract property serializer: DataSerializer[KE, KD, E, D]
Return the data serializer used in the repository.