pagination.py 480 B

1234567891011121314151617181920212223242526
  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. class Page(BaseModel, Generic[T]):
  15. total: int
  16. items: Sequence[T]
  17. limit: Optional[int] = None
  18. offset: Optional[int] = None