pagination

package
v0.0.0-...-5d34579 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyCursorsToEdges

func ApplyCursorsToEdges[E Edge[C], C Cursor[C]](edges []E, after, before *C) (filtered []E, hadEdgesBeforeAfter, hadEdgesAfterBefore bool)

Returns a new slice containing only the edges that are within the range specified by the given cursors.

Types

type Cursor

type Cursor[T any] interface {
	LessThan(T) bool
}

type Edge

type Edge[C Cursor[C]] interface {
	Cursor() C
}

type PageInfo

type PageInfo[C Cursor[C]] struct {
	HasPreviousPage bool
	HasNextPage     bool
	StartCursor     *C
	EndCursor       *C
}

PageInfo represents the information for the current page of results.

func EdgesToReturn

func EdgesToReturn[E Edge[C], C Cursor[C]](edges []E, after, before *C, first, last *int) ([]E, PageInfo[C])

Returns the page of edges that should be returned for the given pagination parameters.

type TimeBasedCursor

type TimeBasedCursor[T any] interface {
	Cursor[T]
	Time() time.Time
}

type TimeBasedRangeQuery

type TimeBasedRangeQuery struct {
	MinTime time.Time
	MaxTime time.Time
	Limit   int
}

func TimeBasedRangeQueries

func TimeBasedRangeQueries[C TimeBasedCursor[C]](after, before *C, atOrAfterTimeIn, beforeTimeIn *time.Time, limit int) []TimeBasedRangeQuery

For a time-based request with the given parameters, returns a list of range queries that should be made to the resolver.

Limit is the maximum number of items to return. If it is negative, the last `limit` items will be returned. If it is zero, there is no limit.

Jump to

Keyboard shortcuts

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