-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
257 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Optional, TypeVar, Union | ||
|
||
from beanie import Document | ||
from beanie.odm.queries.find import FindMany | ||
|
||
from ..api import create_page, resolve_params | ||
from ..bases import AbstractPage, AbstractParams | ||
|
||
TDocument = TypeVar("TDocument", bound=Document) | ||
|
||
|
||
async def paginate( | ||
query: Union[TDocument, FindMany[TDocument]], | ||
params: Optional[AbstractParams] = None, | ||
) -> AbstractPage[TDocument]: | ||
params = resolve_params(params) | ||
raw_params = params.to_raw_params() | ||
|
||
items = await query.find_many(limit=raw_params.limit, skip=raw_params.offset).to_list() | ||
total = await query.count() | ||
|
||
return create_page(items, total, params) | ||
|
||
|
||
__all__ = [ | ||
"paginate", | ||
] |
Oops, something went wrong.