pagination

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 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 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,
	sortBy *FieldDescriptor,
	sortDirection SortDirection,
) (*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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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