How to unpage outside Fastapi #1191
Answered
by
uriyyo
vunhatchuong
asked this question in
Q&A
-
T = TypeVar("T", bound=SQLModel)
PageOptionalParams: TypeAlias = CustomizedPage[Page[T], UseOptionalParams()] Normally I would do: @router.get(
"/",
tags=["Checkin"],
dependencies=[Depends(pagination_ctx(PageOptionalParams[CheckinResponse]))],
) Then I can pass async def filter(
db: AsyncSession,
params: Params | None = Params(),
...,
) -> PageOptionalParams[CheckinResponse]:
page = await paginate(
db,
statement,
params,
)
return page How do I do it in an external script outside of Fastapi? async def main() -> None:
async with get_session() as session:
err, checkin_list = await checkin_crud.filter(
session,
None,
...,
)
return None
if __name__ == "__main__":
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
Answered by
uriyyo
Jun 20, 2024
Replies: 1 comment
-
Hi @vunhatchuong, You can use from fastapi_pagination import Params, set_params, set_page
async def main() -> None:
async with get_session() as session:
with (
set_params(Params(page=1, size=50)),
set_page(PageOptionalParams[CheckinResponse]),
):
err, checkin_list = await checkin_crud.filter(
session,
None,
...,
) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vunhatchuong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @vunhatchuong,
You can use
set_page
andset_params
functions: