Documentation ¶
Overview ¶
Package pagination implements a pager that stores the state in a proto token and uses the altipla-consulting/database API.
Index ¶
- Constants
- Variables
- type Controller
- type ControllerOption
- type InputAdapter
- type PagedController
- func (ctrl PagedController) Checksum() uint32
- func (ctrl *PagedController) Fetch(ctx context.Context, models interface{}) error
- func (ctrl PagedController) HasNextPage() bool
- func (ctrl PagedController) HasPrevPage() bool
- func (ctrl *PagedController) NextPageURL(u *url.URL) *url.URL
- func (ctrl *PagedController) NextPageURLString(r *http.Request) string
- func (ctrl PagedController) OutOfBounds() bool
- func (ctrl PagedController) PageSize() int32
- func (ctrl *PagedController) PrevPageURL(u *url.URL) *url.URL
- func (ctrl *PagedController) PrevPageURLString(r *http.Request) string
- func (ctrl *PagedController) StateAsJSONString() (string, error)
- func (ctrl PagedController) TotalSize() int64
- type Pagerdeprecated
- type TokenController
- func (ctrl TokenController) Checksum() uint32
- func (ctrl *TokenController) Fetch(ctx context.Context, models interface{}) error
- func (ctrl TokenController) HasNextPage() bool
- func (ctrl TokenController) HasPrevPage() bool
- func (ctrl *TokenController) NextPageToken() string
- func (ctrl *TokenController) NextPageURL(u *url.URL) *url.URL
- func (ctrl *TokenController) NextPageURLString(r *http.Request) string
- func (ctrl TokenController) OutOfBounds() bool
- func (ctrl TokenController) PageSize() int32
- func (ctrl *TokenController) PrevPageToken() string
- func (ctrl *TokenController) PrevPageURL(u *url.URL) *url.URL
- func (ctrl *TokenController) PrevPageURLString(r *http.Request) string
- func (ctrl TokenController) TotalSize() int64
- type TokenPaginationRequest
Constants ¶
const (
// DefaultMaxPageSize is the maximum number of items returned in a page by default.
DefaultMaxPageSize = 1000
)
Variables ¶
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
func FromAPI(msg TokenPaginationRequest) InputAdapter
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.
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.
type TokenPaginationRequest ¶ added in v1.107.0
TokenPaginationRequest is implemented by the generated Protobuf structs if using the Google guidelines for API pagination.