pagination.py 550 B

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