paginator

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCursor = errors.New("invalid cursor for paginating")
	ErrInvalidLimit  = errors.New("limit should be greater than 0")
	ErrInvalidModel  = errors.New("model fields should match rules or keys specified for paginator")
	ErrInvalidOrder  = errors.New("order should be ASC or DESC")
	ErrNoRule        = errors.New("paginator should have at least one rule")
)

Errors for paginator

Functions

This section is empty.

Types

type Config

type Config struct {
	Rules         []Rule
	Keys          []string
	Limit         int
	Order         Order
	After         string
	Before        string
	AllowTupleCmp Flag
}

Config for paginator

func (*Config) Apply

func (c *Config) Apply(p *Paginator)

Apply applies config to paginator

type Cursor

type Cursor = cursor.Cursor

Cursor re-exports cursor.Cursor

type CustomType added in v2.3.0

type CustomType struct {
	Meta interface{}
	Type reflect.Type
}

CustomType for paginator. It provides extra info needed to paginate across custom types (e.g. JSON)

type Flag added in v2.6.0

type Flag string
const (
	TRUE  Flag = "TRUE"
	FALSE Flag = "FALSE"
)

type Option

type Option interface {
	Apply(p *Paginator)
}

Option for paginator

func WithAfter

func WithAfter(c string) Option

WithAfter configures after cursor for paginator

func WithAllowTupleCmp added in v2.6.0

func WithAllowTupleCmp(flag Flag) Option

WithAllowTupleCmp enables tuple comparison optimization

func WithBefore

func WithBefore(c string) Option

WithBefore configures before cursor for paginator

func WithKeys

func WithKeys(keys ...string) Option

WithKeys configures keys for paginator

func WithLimit

func WithLimit(limit int) Option

WithLimit configures limit for paginator

func WithOrder

func WithOrder(order Order) Option

WithOrder configures order for paginator

func WithRules

func WithRules(rules ...Rule) Option

WithRules configures rules for paginator

type Order

type Order string

Order type for order

const (
	ASC  Order = "ASC"
	DESC Order = "DESC"
)

Orders

type Paginator

type Paginator struct {
	// contains filtered or unexported fields
}

Paginator a builder doing pagination

func New

func New(opts ...Option) *Paginator

New creates paginator

func (*Paginator) GetCursorDecoder added in v2.5.0

func (p *Paginator) GetCursorDecoder() *cursor.Decoder

GetCursorDecoder returns cursor decoder based on paginator rules

func (*Paginator) GetCursorEncoder added in v2.5.0

func (p *Paginator) GetCursorEncoder() *cursor.Encoder

GetCursorEncoder returns cursor encoder based on paginator rules

func (*Paginator) Paginate

func (p *Paginator) Paginate(db *gorm.DB, dest interface{}) (result *gorm.DB, c Cursor, err error)

Paginate paginates data

func (*Paginator) SetAfterCursor

func (p *Paginator) SetAfterCursor(afterCursor string)

SetAfterCursor sets paging after cursor

func (*Paginator) SetAllowTupleCmp added in v2.6.0

func (p *Paginator) SetAllowTupleCmp(allow bool)

SetAllowTupleCmp enables or disables tuple comparison optimization

func (*Paginator) SetBeforeCursor

func (p *Paginator) SetBeforeCursor(beforeCursor string)

SetBeforeCursor sets paging before cursor

func (*Paginator) SetKeys

func (p *Paginator) SetKeys(keys ...string)

SetKeys sets paging keys

func (*Paginator) SetLimit

func (p *Paginator) SetLimit(limit int)

SetLimit sets paging limit

func (*Paginator) SetOrder

func (p *Paginator) SetOrder(order Order)

SetOrder sets paging order

func (*Paginator) SetRules

func (p *Paginator) SetRules(rules ...Rule)

SetRules sets paging rules

type Rule

type Rule struct {
	Key             string
	Order           Order
	SQLRepr         string
	SQLType         *string
	NULLReplacement interface{}
	CustomType      *CustomType
}

Rule for paginator

Jump to

Keyboard shortcuts

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