Documentation ¶
Overview ¶
Package pagination provides functionalities related to cursor-based pagination.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection interface { Query(ctx context.Context, sql string, optionsAndArgs ...any) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row }
Connection is used to represent a DB connection
type CursorFunc ¶
type CursorFunc func(cp CursorPaginatable) (*string, error)
CursorFunc creates an opaque cursor string
type CursorPaginatable ¶
CursorPaginatable implements functions needed to resolve fields for cursor pagination
type ExtraOptionFunc ¶ added in v0.19.0
type ExtraOptionFunc func(*extraOptions)
ExtraOptionFunc is a function to set extra options
func WithSortByField ¶ added in v0.19.0
func WithSortByField(field *FieldDescriptor, direction SortDirection) ExtraOptionFunc
WithSortByField sets the sort by field and direction
func WithSortByTransform ¶ added in v0.19.0
func WithSortByTransform(f SortTransformFunc) ExtraOptionFunc
WithSortByTransform sets the optional sort by transform function
type FieldDescriptor ¶
FieldDescriptor defines a field descriptor
type MockConnection ¶
MockConnection is an autogenerated mock type for the Connection type
func NewMockConnection ¶
func NewMockConnection(t mockConstructorTestingTNewMockConnection) *MockConnection
NewMockConnection creates a new instance of MockConnection. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
type PageInfo ¶
type PageInfo struct { Cursor CursorFunc TotalCount int32 HasNextPage bool HasPreviousPage bool }
PageInfo contains the page information
type PaginatedQueryBuilder ¶
type PaginatedQueryBuilder struct {
// contains filtered or unexported fields
}
PaginatedQueryBuilder represents a paginated DB query
func NewPaginatedQueryBuilder ¶
func NewPaginatedQueryBuilder( options *Options, primaryKey *FieldDescriptor, extraOpts ...ExtraOptionFunc, ) (*PaginatedQueryBuilder, error)
NewPaginatedQueryBuilder returns a PaginatedQueryBuilder
func (*PaginatedQueryBuilder) Execute ¶
func (p *PaginatedQueryBuilder) Execute(ctx context.Context, conn Connection, query *goqu.SelectDataset) (PaginatedRows, error)
Execute executes the paginated query using the DB Connection
type PaginatedRows ¶
PaginatedRows contains the paginated query results
type SortDirection ¶
type SortDirection string
SortDirection indicates the direction for sorting results
const ( AscSort SortDirection = "ASC" DescSort SortDirection = "DESC" )
SortDirection constants
type SortTransformFunc ¶ added in v0.19.0
SortTransformFunc is a function for transforming the sort by field used in the query