pagination

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: BSD-3-Clause Imports: 2 Imported by: 18

README

go-pagination

Go package implementing common interfaces for paginating queries and query results.

Important

This is work in progress. Things are starting to settle down but may still be subject to change.

Documentation

Go Reference

Documentation is incomplete at this time.

Documentation

Overview

package pagination provides common interfaces for paginating queries and query results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PagesForCount

func PagesForCount(opts Options, total_count int64) int64

PagesForCount returns the number of pages that total_count will span using criteria defined in opts.

Types

type Method added in v0.1.1

type Method uint8

Method defines the type of pagination Options or Results.

const (
	// Countable is a page-based or numbered pagination implementation
	Countable Method = iota
	// Cursor is a token or cursor-based pagination implementation where the total number of results is unknown
	Cursor
)

type Options added in v0.1.1

type Options interface {
	// Get or set the number of results to return in a Results
	PerPage(...int64) int64
	// Get or set current page to return query results for
	Spill(...int64) int64
	// Get or set the name of the column to use when paginating results
	Column(...string) string
	// Get or set the pointer (page number or cursor) for the next set of query results
	Pointer(...interface{}) interface{}
	// Return the Method type associated with Options
	Method() Method
}

Options provides a common interface for criteria used to paginate a query.

type Results added in v0.1.1

type Results interface {
	// The total number of results for a query.
	Total() int64
	// The number of results per page for a query.
	PerPage() int64
	// The current page number (offset) for a paginated query response.
	Page() int64
	// The total number of pages for a paginated query response.
	Pages() int64
	// The value to use to advance to the next set of results in a query response.
	Next() interface{}
	// The value to use to rewind to the previous set of results in a query response.
	Previous() interface{}
	// The URL to the next set of results in a query response
	NextURL(t *uritemplates.UriTemplate) (string, error)
	// The URL to the previous set of results in a query response
	PreviousURL(*uritemplates.UriTemplate) (string, error)
	// Return the Method type associated with Results
	Method() Method
}

Results provides an interface for pagination information for a query response.

Directories

Path Synopsis
package countable provides implementions of the pagintion.Options and pagination.Results interfaces for use with page-based or numbered pagination.
package countable provides implementions of the pagintion.Options and pagination.Results interfaces for use with page-based or numbered pagination.
package cursor provides implementions of the pagintion.Options and pagination.Results interfaces for use with cursor or token-based pagination.
package cursor provides implementions of the pagintion.Options and pagination.Results interfaces for use with cursor or token-based pagination.

Jump to

Keyboard shortcuts

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