CountedPaginatedList#
- class safir.database.CountedPaginatedList(entries, next_cursor, prev_cursor, count)#
Bases:
PaginatedList,GenericPaginated SQL results with pagination metadata and total count.
Holds a paginated list of any Pydantic type, complete with a count and cursors. Can hold any type of entry and any type of cursor, but implicitly requires the entry type be one that is meaningfully paginated by that type of cursor.
- Parameters:
next_cursor (
Optional[TypeVar(C, bound=PaginationCursor)])prev_cursor (
Optional[TypeVar(C, bound=PaginationCursor)])count (
int)
Attributes Summary
Total number of entries if queried without pagination.
A batch of entries.
Cursor for the next batch of entries.
Cursor for the previous batch of entries.
Methods Summary
from_transform(other, transform)Build a new paginated list via a transform of each member.
Attributes Documentation
-
count:
int= <dataclasses._MISSING_TYPE object># Total number of entries if queried without pagination.
-
entries:
list[TypeVar(E, bound=BaseModel)] = <dataclasses._MISSING_TYPE object># A batch of entries.
-
next_cursor:
Optional[TypeVar(C, bound=PaginationCursor)] = <dataclasses._MISSING_TYPE object># Cursor for the next batch of entries.
-
prev_cursor:
Optional[TypeVar(C, bound=PaginationCursor)] = <dataclasses._MISSING_TYPE object># Cursor for the previous batch of entries.
Methods Documentation
- classmethod from_transform(other, transform)#
Build a new paginated list via a transform of each member.
Some web services will need to transform the members of a paginated list, to convert from internal to API models for example, without losing the pagination information. This method performs that operation, returning a new paginated list for the new type with the same pagination details.
- Parameters:
transform (
Callable[[TypeVar(F, bound=BaseModel)],TypeVar(E, bound=BaseModel)]) – A function that converts from the entry type of this list to the entry type of the new list. This will be called for each entry.other (
PaginatedList[TypeVar(F, bound=BaseModel),TypeVar(C, bound=PaginationCursor)])
- Returns:
A new paginated list holding the transformed entries but with the same cursors.
- Return type: