pagination.py 526 B

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