Skip to content

Commit

Permalink
✨ Support total parameter for tortoise ext (#1269)
Browse files Browse the repository at this point in the history
Co-authored-by: Yurii Karabas <[email protected]>
  • Loading branch information
waketzheng and uriyyo authored Sep 8, 2024
1 parent 49734f5 commit f9bdf59
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fastapi_pagination/ext/tortoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ async def paginate(
*,
transformer: Optional[AsyncItemsTransformer] = None,
additional_data: Optional[AdditionalData] = None,
total: Optional[int] = None,
) -> Any:
params, raw_params = verify_params(params, "limit-offset")

if not isinstance(query, QuerySet):
query = query.all()

total = await query.count() if raw_params.include_total else None
if total is None and raw_params.include_total:
total = await query.count()
items = await generic_query_apply_params(_generate_query(query, prefetch_related), raw_params).all()
t_items = await apply_items_transformer(items, transformer, async_=True)

Expand Down

0 comments on commit f9bdf59

Please sign in to comment.