pagination.py 496 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. # (c) Nelen & Schuurmans
  3. from typing import Generic, Optional, Sequence, TypeVar
  4. from pydantic import BaseModel
  5. from pydantic.generics import GenericModel
  6. __all__ = ["Page", "PageOptions"]
  7. T = TypeVar("T")
  8. class PageOptions(BaseModel):
  9. limit: int
  10. offset: int = 0
  11. order_by: str = "id"
  12. ascending: bool = True
  13. class Page(GenericModel, Generic[T]):
  14. total: int
  15. items: Sequence[T]
  16. limit: Optional[int] = None
  17. offset: Optional[int] = None