Add get_by_ids

This commit is contained in:
Edkar Chachati
2023-12-24 14:41:32 -04:00
parent 61c8636c43
commit ddbefab7d9
2 changed files with 29 additions and 0 deletions

View File

@ -52,6 +52,25 @@ class CRUDManager:
)
return obj
def get_by_ids(self, ids: list[int]) -> list[ModelType]:
"""
The function retrieves a list of model objects from the database based
on their primary keys.
Arguments:
* `ids`: The parameter `ids` is a list of integers. It is used to
identify a list of objects in the database based on their primary key
values.
Returns:
The `get_by_ids` method is returning a list of objects of type
`ModelType`.
"""
query = select(self.model).where(self.model.id.in_(ids))
return self.db.exec(query).all()
def list(self, query: QueryLike = None) -> list[ModelType]:
"""
The function returns a list of all the records in the database that