pagination

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPageSize int32 = 100
	MaximumPageSize int32 = 5000
	CursorDuration        = 24 * time.Hour
)

Variables

View Source
var (
	ErrMissingExpiration  = errors.New("cursor does not have an expires timestamp")
	ErrCursorExpired      = errors.New("cursor has expired and is no longer useable")
	ErrUnparsableToken    = errors.New("could not parse the next page token")
	ErrTokenQueryMismatch = errors.New("cannot change query parameters during pagination")
)
View Source
var File_pagination_pagination_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Cursor

type Cursor struct {

	// The start index is the ID at the beginning of the page and is used for previous
	// page queries, whereas the end index is the last ID on the page and is used to
	// compute the next page for the query. Ensure that IDs are montonically increasing
	// such as autoincrement IDs or ULIDs (do not use UUIDs).
	StartIndex string `protobuf:"bytes,1,opt,name=start_index,json=startIndex,proto3" json:"start_index,omitempty"`
	EndIndex   string `protobuf:"bytes,2,opt,name=end_index,json=endIndex,proto3" json:"end_index,omitempty"`
	// The maximum number of results per page.
	PageSize int32 `protobuf:"varint,3,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
	// The timestamp when the cursor is no longer valid.
	Expires *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=expires,proto3" json:"expires,omitempty"`
	// contains filtered or unexported fields
}

Key-Index Cursors are useful for high-performance pagination that do not require Postgres Cursors managed by an open transaction. The cursor specifies the current page of results so that the next/previous pages can be calculated from the query. Cursors also specify an expiration so that a page token cannot be replayed forever. Note that Key-Index cursors require the original query to correctly order the index, this cursor type assumes that no ordering or filtering has been applied.

The cursor object is serialized and base64 encoded to be sent as a next_page_token in a paginated request. Protocol buffers ensures the most compact representation.

func New

func New(startIndex, endIndex string, pageSize int32) *Cursor

func Parse

func Parse(token string) (cursor *Cursor, err error)

func (*Cursor) Descriptor deprecated

func (*Cursor) Descriptor() ([]byte, []int)

Deprecated: Use Cursor.ProtoReflect.Descriptor instead.

func (*Cursor) GetEndIndex

func (x *Cursor) GetEndIndex() string

func (*Cursor) GetExpires

func (x *Cursor) GetExpires() *timestamppb.Timestamp

func (*Cursor) GetPageSize

func (x *Cursor) GetPageSize() int32

func (*Cursor) GetStartIndex

func (x *Cursor) GetStartIndex() string

func (*Cursor) HasExpired

func (c *Cursor) HasExpired() (bool, error)

func (*Cursor) IsZero

func (c *Cursor) IsZero() bool

func (*Cursor) NextPageToken

func (c *Cursor) NextPageToken() (token string, err error)

func (*Cursor) ProtoMessage

func (*Cursor) ProtoMessage()

func (*Cursor) ProtoReflect

func (x *Cursor) ProtoReflect() protoreflect.Message

func (*Cursor) Reset

func (x *Cursor) Reset()

func (*Cursor) String

func (x *Cursor) String() string

Jump to

Keyboard shortcuts

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