Documentation
¶
Overview ¶
Package pagination provides a generic cursor-based pagination implementation. It handles direction detection, n+1 pattern processing, and cursor building for stores that need paginated list operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[T any] struct { Limit int Order string // "asc" or "desc" - user's requested order Next string // next cursor (empty if none) Prev string // prev cursor (empty if none) Fetch func(context.Context, QueryInput) ([]T, error) Cursor Cursor[T] }
Config contains all parameters for a paginated query.
type Cursor ¶
type Cursor[T any] struct { Encode func(T) string // item → cursor string Decode func(string) (string, error) // cursor string → position for query }
Cursor groups encode/decode functions for cursor serialization. These are paired together to support versioning and backward compatibility.
type Direction ¶
type Direction int
Direction indicates whether pagination is moving forward or backward.
type QueryInput ¶
type QueryInput struct {
Limit int
Compare string // "<" or ">" - cursor comparison operator
SortDir string // "asc" or "desc" - query sort direction (may differ from user's Order)
CursorPos string // decoded cursor position (empty if first page)
}
QueryInput is passed to the Fetch function with computed query parameters.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package paginationtest provides a reusable test suite for cursor-based pagination.
|
Package paginationtest provides a reusable test suite for cursor-based pagination. |
Click to show internal directories.
Click to hide internal directories.