page

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor[T OrderField] struct {
	Size     int
	Position Position
	Key      *CursorKey
	OrderBy  OrderBy[T]
}

func NewCursor

func NewCursor[T OrderField](size int, from *CursorKey, pos Position, orderBy OrderBy[T]) *Cursor[T]

func (*Cursor[T]) SQLArguments

func (c *Cursor[T]) SQLArguments() pgx.NamedArgs

func (*Cursor[T]) SQLFragment

func (c *Cursor[T]) SQLFragment() string

type CursorKey

type CursorKey struct {
	ID    gid.GID
	Value any
}
var (
	CursorKeyNil CursorKey

	ErrInvalidFormat = errors.New("invalid format")
)

func NewCursorKey

func NewCursorKey(id gid.GID, value any) CursorKey

func ParseCursorKey

func ParseCursorKey(s string) (CursorKey, error)

func (CursorKey) Bytes

func (ck CursorKey) Bytes() []byte

func (CursorKey) FieldValue added in v0.2.0

func (ck CursorKey) FieldValue() any

func (CursorKey) MarshalBinary

func (ck CursorKey) MarshalBinary() ([]byte, error)

func (CursorKey) MarshalJSON added in v0.2.0

func (ck CursorKey) MarshalJSON() ([]byte, error)

func (CursorKey) MarshalText

func (ck CursorKey) MarshalText() ([]byte, error)

func (CursorKey) String

func (ck CursorKey) String() string

func (*CursorKey) UnmarshalBinary

func (ck *CursorKey) UnmarshalBinary(data []byte) error

func (*CursorKey) UnmarshalJSON added in v0.2.0

func (ck *CursorKey) UnmarshalJSON(data []byte) error

func (*CursorKey) UnmarshalText

func (ck *CursorKey) UnmarshalText(data []byte) error

type OrderBy added in v0.2.0

type OrderBy[T OrderField] struct {
	Field     T
	Direction OrderDirection
}

type OrderDirection added in v0.2.0

type OrderDirection string
const (
	OrderDirectionAsc  OrderDirection = "ASC"
	OrderDirectionDesc OrderDirection = "DESC"
)

func (OrderDirection) MarshalText added in v0.2.0

func (od OrderDirection) MarshalText() ([]byte, error)

func (OrderDirection) String added in v0.2.0

func (od OrderDirection) String() string

func (*OrderDirection) UnmarshalText added in v0.2.0

func (od *OrderDirection) UnmarshalText(data []byte) error

type OrderField added in v0.2.0

type OrderField interface {
	Column() string
	fmt.Stringer
}

type Page

type Page[T Paginable[U], U OrderField] struct {
	Info   *PageInfo
	Cursor *Cursor[U]
	Data   []T
}

func NewPage

func NewPage[T Paginable[U], U OrderField](data []T, c *Cursor[U]) *Page[T, U]

func (*Page[T, U]) First

func (p *Page[T, U]) First() T

func (*Page[T, U]) Last

func (p *Page[T, U]) Last() T

type PageInfo

type PageInfo struct {
	HasNext bool
	HasPrev bool
}

type Paginable

type Paginable[T OrderField] interface {
	CursorKey(orderBy T) CursorKey
}

type Position

type Position string
const (
	DefaultCursorSize = 25

	Tail Position = "TAIL"
	Head Position = "HEAD"
)

type StringCursorKey added in v0.4.0

type StringCursorKey struct {
	ID    string
	Value any
}

StringCursorKey is a cursor key for string IDs

Jump to

Keyboard shortcuts

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