CountedPaginatedList#

class safir.database.CountedPaginatedList(entries, next_cursor, prev_cursor, count)#

Bases: PaginatedList, Generic

Paginated 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:

Attributes Summary

count

Total number of entries if queried without pagination.

entries

A batch of entries.

next_cursor

Cursor for the next batch of entries.

prev_cursor

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:
Returns:

A new paginated list holding the transformed entries but with the same cursors.

Return type:

PaginatedList

This page was last modified on .