pagination

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

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

type CursorPaginatable interface {
	ResolveMetadata(key string) (string, error)
}

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

type FieldDescriptor struct {
	Key   string
	Table string
	Col   string
}

FieldDescriptor defines a field descriptor

type MockConnection

type MockConnection struct {
	mock.Mock
}

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.

func (*MockConnection) Query

func (_m *MockConnection) Query(ctx context.Context, sql string, optionsAndArgs ...interface{}) (pgx.Rows, error)

Query provides a mock function with given fields: ctx, sql, optionsAndArgs

func (*MockConnection) QueryRow

func (_m *MockConnection) QueryRow(ctx context.Context, sql string, optionsAndArgs ...interface{}) pgx.Row

QueryRow provides a mock function with given fields: ctx, sql, optionsAndArgs

type Options

type Options struct {
	Before *string
	After  *string
	First  *int32
	Last   *int32
}

Options contain the cursor based pagination options

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

type PaginatedRows interface {
	pgx.Rows
	GetPageInfo() *PageInfo
	Finalize(resultsPtr any) error
}

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

type SortTransformFunc func(string) string

SortTransformFunc is a function for transforming the sort by field used in the query

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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