Skip to content

Commit

Permalink
Fix issue with databases + sqlalchemy 2.0 (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
uriyyo authored May 10, 2024
1 parent e029be4 commit f4639f1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fastapi_pagination/ext/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
from typing import Any, List, Optional

from databases import Database
from sqlalchemy import func, select
from sqlalchemy.sql import Select

from ..api import apply_items_transformer, create_page
from ..bases import AbstractParams
from ..types import AdditionalData, AsyncItemsTransformer
from ..utils import verify_params
from .sqlalchemy import create_paginate_query
from .sqlalchemy import create_count_query, create_paginate_query


async def paginate(
Expand All @@ -23,11 +22,12 @@ async def paginate(
transformer: Optional[AsyncItemsTransformer] = None,
additional_data: Optional[AdditionalData] = None,
convert_to_mapping: bool = True,
use_subquery: bool = True,
) -> Any:
params, raw_params = verify_params(params, "limit-offset")

if raw_params.include_total:
total = await db.fetch_val(select([func.count()]).select_from(query.order_by(None).alias()))
total = await db.fetch_val(create_count_query(query, use_subquery=use_subquery))
else:
total = None

Expand Down

0 comments on commit f4639f1

Please sign in to comment.