pagination.py 535 B

1234567891011121314151617181920212223242526272829
  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 .types import Id
  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. cursor: Optional[Id] = None
  16. class Page(BaseModel, Generic[T]):
  17. total: int
  18. items: Sequence[T]
  19. limit: Optional[int] = None
  20. offset: Optional[int] = None