Skip to content

Commit

Permalink
Add Model.fetchmany (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
CircuitSacul committed May 31, 2022
1 parent 5b593bf commit 60e5e92
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apgorm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
UpdateQueryBuilder,
)
from .undefined import UNDEF
from .utils.lazy_list import LazyList

if TYPE_CHECKING: # pragma: no cover
from .connection import Connection
Expand Down Expand Up @@ -235,6 +236,18 @@ async def fetch(
raise ModelNotFound(cls, values)
return res

@classmethod
async def fetchmany(
cls: Type[_SELF], con: Connection | None, /, **values: Any
) -> LazyList[dict[str, Any], _SELF]:
"""Fetch multiple models from the database.
Returns:
LazyList[dict[str, Any], Model]: The list of models.
"""

return await cls.fetch_query(con=con).where(**values).fetchmany()

@classmethod
async def count(
cls: Type[_SELF], con: Connection | None = None, /, **values: Any
Expand Down

0 comments on commit 60e5e92

Please sign in to comment.