pagination.py 513 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. __all__ = ["Page", "PageOptions"]
  8. T = TypeVar("T")
  9. class PageOptions(BaseModel):
  10. limit: int
  11. offset: int = 0
  12. order_by: str = "id"
  13. ascending: bool = True
  14. cursor: Optional[str] = None
  15. class Page(BaseModel, Generic[T]):
  16. total: int
  17. items: Sequence[T]
  18. limit: Optional[int] = None
  19. offset: Optional[int] = None