DB Pagination¶
The Pagination class is a tool for managing paginated rows from the database.
It requires the db extra to be installed:
It can be imported from fluid.db:
fluid.db.Pagination
¶
Bases: NamedTuple
Cursor-based pagination over a database table.
The order_by_fields must uniquely identify a row: the values of those
fields, taken together, must be distinct for every row matched by the
query. The cursor stores nothing but those values, so it can only resume
from an unambiguous position. Add a unique column, usually the primary
key, as the last ordering field when the other fields can tie:
When the ordering is not unique, rows sharing the same ordering values can be repeated across consecutive pages, and rows can be missed entirely because the database is free to order tied rows differently between the two queries.
create
classmethod
¶
Factory method to create a Pagination instance, decoding the cursor if provided.
If the cursor is provided, filters, limit and search are extracted from it, and the provided values for these parameters are ignored.
The order_by_fields must uniquely identify a row, otherwise pages can
repeat or miss rows.
| PARAMETER | DESCRIPTION |
|---|---|
*order_by_fields
|
Fields to order results by
TYPE:
|
cursor
|
Encoded pagination cursor from a previous response
TYPE:
|
limit
|
Maximum number of results per page; defaults to settings.DEFAULT_PAGINATION_LIMIT
TYPE:
|
filters
|
Filters to apply to the query
TYPE:
|
search
|
Full-text search configuration
TYPE:
|
desc
|
Order results in descending order
TYPE:
|
Source code in fluid/db/pagination.py
execute
async
¶
Execute the paginated query and return the results along with the next cursor.
| PARAMETER | DESCRIPTION |
|---|---|
db
|
Database instance to execute the query on
TYPE:
|
table
|
SQLAlchemy table to query
TYPE:
|
conn
|
Optional existing connection to reuse
TYPE:
|