pagination

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2025 License: Apache-2.0 Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFirstOrLastMissing = errors.New("first or last is required")
	ErrGreaterThanMaxRow  = errors.New("first or last is greater than maxRow")
)

Functions

func LimitPerRow

func LimitPerRow(partitionBy string, limit, offset int, orderBy ...sql.Querier) func(s *sql.Selector)

LimitPerRow returns a query modifier that limits the number of (edges) rows returned by the given partition and pagination. This helper function is used mainly by the paginated API to override the default Limit behavior for limit returned per node and not limit for all query.

func NeedLimit added in v0.4.1

func NeedLimit(first, last *int, maxRow int) error

NeedLimit returns an error if first or last is not set, if maxRow is set and first or last is greater than maxRow, it returns an error.

func WithSimplePagination

func WithSimplePagination(ctx context.Context, sp *SimplePagination) context.Context

WithSimplePagination returns a new context with the given SimplePagination.

Types

type SimplePagination

type SimplePagination struct {
	CurrentIndex int
	PageIndex    int
}

SimplePagination is a simple pagination implementation.

func NewSimplePagination

func NewSimplePagination(p, c string) (sp *SimplePagination, err error)

NewSimplePagination creates a new SimplePagination from the given page and count. If both are empty, it returns nil.

func SimplePaginationFromContext

func SimplePaginationFromContext(ctx context.Context) (*SimplePagination, bool)

SimplePaginationFromContext returns the SimplePagination from the given context.

func (*SimplePagination) Offset

func (sp *SimplePagination) Offset(first, last *int) (offset int)

Offset returns the offset for the given first and last values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL