pagination

package
v1.186.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package pagination implements a pager that stores the state in a proto token and uses the altipla-consulting/database API.

Index

Constants

View Source
const (
	// DefaultMaxPageSize is the maximum number of items returned in a page by default.
	DefaultMaxPageSize = 1000
)

Variables

View Source
var (
	ErrInvalidToken     = errors.New("pagination: invalid token")
	ErrChecksumMismatch = errors.New("pagination: checksum mismatch")
)

Functions

This section is empty.

Types

type Controller added in v1.107.0

type Controller interface {
	// contains filtered or unexported methods
}

Controller is implemented by all the pagination controllers of this package.

type ControllerOption added in v1.107.0

type ControllerOption func(Controller)

ControllerOption configures a paginator.

func WithMaxPageSize added in v1.107.0

func WithMaxPageSize(maxPageSize int32) ControllerOption

WithMaxPageSize changes the default maximum page size of 1000.

func WithRDBInclude added in v1.107.0

func WithRDBInclude(includes ...rdb.IncludeOption) ControllerOption

WithRDBInclude brings linked models when querying the database. Cannot be used with NewSQL.

type InputAdapter added in v1.107.0

type InputAdapter func(Controller)

InputAdapter reads multiple kind of sources to configure the pagination.

func FromAPI added in v1.107.0

FromAPI configures the pagination from a standard gRPC request message.

func FromEmpty added in v1.107.0

func FromEmpty() InputAdapter

FromEmpty configures the pagination with an empty input. Used mostly in tests or other internal helpers.

func FromPaged added in v1.107.0

func FromPaged(pageSize int32, page int32, checksum uint32) InputAdapter

FromPaged directly configures the input parameters of a paged pagination.

func FromRequest added in v1.107.0

func FromRequest(r *http.Request) InputAdapter

FromRequest reads the input parameters from a HTTP request.

func FromToken added in v1.107.0

func FromToken(pageSize int32, token string) InputAdapter

FromToken directly configures the input parameters of a token pagination.

type PagedController added in v1.107.0

type PagedController struct {
	// contains filtered or unexported fields
}

func NewRDBPaged added in v1.107.0

func NewRDBPaged(q *rdb.Query, input InputAdapter, opts ...ControllerOption) *PagedController

NewRDBToken creates a paginator for a RavenDB query using page numbers.

func NewSQLPaged added in v1.107.0

func NewSQLPaged(q *database.Collection, input InputAdapter, opts ...ControllerOption) *PagedController

NewSQLToken creates a paginator for a MySQL query using page numbers.

func (PagedController) Checksum added in v1.107.0

func (ctrl PagedController) Checksum() uint32

Checksum returns the internal checksum that must validate to perform the query.

func (*PagedController) Fetch added in v1.107.0

func (ctrl *PagedController) Fetch(ctx context.Context, models interface{}) error

Fetch obtains the requested page of items.

func (PagedController) HasNextPage added in v1.107.0

func (ctrl PagedController) HasNextPage() bool

HasNextPage returns true if there is a next page.

func (PagedController) HasPrevPage added in v1.107.0

func (ctrl PagedController) HasPrevPage() bool

HasPrevPage returns true if there is a previous page.

func (*PagedController) NextPageURL added in v1.107.0

func (ctrl *PagedController) NextPageURL(u *url.URL) *url.URL

NextPageURL modifies the URL to point to the next page.

func (*PagedController) NextPageURLString added in v1.107.0

func (ctrl *PagedController) NextPageURLString(r *http.Request) string

NextPageURLString returns a new URL based on the current one for the next page.

func (PagedController) OutOfBounds added in v1.107.0

func (ctrl PagedController) OutOfBounds() bool

OutOfBounds returns true if the requested page is out of bounds.

func (PagedController) PageSize added in v1.107.0

func (ctrl PagedController) PageSize() int32

PageSize returns the page size.

func (*PagedController) PrevPageURL added in v1.107.0

func (ctrl *PagedController) PrevPageURL(u *url.URL) *url.URL

PrevPageURL modifies the URL to point to the previous page.

func (*PagedController) PrevPageURLString added in v1.107.0

func (ctrl *PagedController) PrevPageURLString(r *http.Request) string

PrevPageURLString returns a new URL based on the current one for the previous page.

func (*PagedController) StateAsJSONString added in v1.107.0

func (ctrl *PagedController) StateAsJSONString() (string, error)

StateAsJSONString returns an overview of the paginator state in JSON format suitable for use in client components like altipla/ui-v2.

func (PagedController) TotalSize added in v1.107.0

func (ctrl PagedController) TotalSize() int64

TotalSize returns the total results of the query.

type Pager deprecated

type Pager struct {
	NextPageToken string
	TotalSize     int32
	PrevPageToken string
	// contains filtered or unexported fields
}

Deprecated: Use NewSQLToken instead.

func NewPager deprecated

func NewPager(c *database.Collection) *Pager

Deprecated: Use NewSQLToken instead.

func (*Pager) Fetch deprecated

func (pager *Pager) Fetch(ctx context.Context, models interface{}) error

Deprecated: Use NewSQLToken instead.

func (*Pager) SetInputs deprecated

func (pager *Pager) SetInputs(pageToken string, pageSize int32)

Deprecated: Use NewSQLToken instead.

type TokenController added in v1.107.0

type TokenController struct {
	// contains filtered or unexported fields
}

func NewRDBToken added in v1.107.0

func NewRDBToken(q *rdb.Query, input InputAdapter, opts ...ControllerOption) *TokenController

NewRDBToken creates a paginator for a RavenDB query using tokens.

func NewSQLToken added in v1.107.0

func NewSQLToken(q *database.Collection, input InputAdapter, opts ...ControllerOption) *TokenController

NewSQLToken creates a paginator for a MySQL query using tokens.

func (TokenController) Checksum added in v1.107.0

func (ctrl TokenController) Checksum() uint32

Checksum returns the internal checksum that must validate to perform the query.

func (*TokenController) Fetch added in v1.107.0

func (ctrl *TokenController) Fetch(ctx context.Context, models interface{}) error

Fetch obtains the requested page of items.

func (TokenController) HasNextPage added in v1.107.0

func (ctrl TokenController) HasNextPage() bool

HasNextPage returns true if there is a next page.

func (TokenController) HasPrevPage added in v1.107.0

func (ctrl TokenController) HasPrevPage() bool

HasPrevPage returns true if there is a previous page.

func (*TokenController) NextPageToken added in v1.107.0

func (ctrl *TokenController) NextPageToken() string

NextPageToken returns a token that can be used to fetch the next page.

func (*TokenController) NextPageURL added in v1.107.0

func (ctrl *TokenController) NextPageURL(u *url.URL) *url.URL

NextPageURL modifies the URL to point to the next page.

func (*TokenController) NextPageURLString added in v1.107.0

func (ctrl *TokenController) NextPageURLString(r *http.Request) string

NextPageURLString returns a new URL based on the current one for the next page.

func (TokenController) OutOfBounds added in v1.107.0

func (ctrl TokenController) OutOfBounds() bool

OutOfBounds returns true if the requested page is out of bounds.

func (TokenController) PageSize added in v1.107.0

func (ctrl TokenController) PageSize() int32

PageSize returns the page size.

func (*TokenController) PrevPageToken added in v1.107.0

func (ctrl *TokenController) PrevPageToken() string

PrevPageToken returns a token that can be used to fetch the previous page.

func (*TokenController) PrevPageURL added in v1.107.0

func (ctrl *TokenController) PrevPageURL(u *url.URL) *url.URL

PrevPageURL modifies the URL to point to the previous page.

func (*TokenController) PrevPageURLString added in v1.107.0

func (ctrl *TokenController) PrevPageURLString(r *http.Request) string

PrevPageURLString returns a new URL based on the current one for the previous page.

func (TokenController) TotalSize added in v1.107.0

func (ctrl TokenController) TotalSize() int64

TotalSize returns the total results of the query.

type TokenPaginationRequest added in v1.107.0

type TokenPaginationRequest interface {
	GetPageSize() int32
	GetPageToken() string
}

TokenPaginationRequest is implemented by the generated Protobuf structs if using the Google guidelines for API pagination.

Jump to

Keyboard shortcuts

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