INNER CODE UNIT · Python

total_pages

dialoguemd/fastapi-sqla · fastapi_sqla/async_pagination.py:35

    total_pages = math.ceil(total_items / limit)
    page_number = math.floor(offset / limit + 1)
    query = query.offset(offset).limit(limit)
    result = await session.execute(query)
    data = iter(
        cast(Iterator, result.unique().scalars() if scalars else result.mappings())
    )
    return Page(
        data=data,  # type: ignore # Expected to be a list
        meta=Meta(
            offset=offset,
            total_items=total_items,
            total_pages=total_pages,
            page_number=page_number,
        ),
    )

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…