filter

package
v2.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package filter ... Deprecated: use github.com/n-r-w/squirrel

Index

Constants

View Source
const (
	// ASC ascending sort order
	ASC = OrderType(0)
	// DESC descending sort order
	DESC = OrderType(1)
)

Variables

View Source
var (
	// ErrOrderAliasNotFound SQL alias for orderID was not found
	ErrOrderAliasNotFound = errors.New("sql alias for orderID not found")

	// ErrUnknownOrderType unknown sort type
	ErrUnknownOrderType = errors.New("unknown order type")
)

Functions

func NewInCond

func NewInCond[T any](sqlName string, values []T) *inCond

NewInCond returns an object for creating an IN condition in SQL

func NewSelectBuilder

func NewSelectBuilder(opts ...option) (sq.SelectBuilder, error)

NewSelectBuilder returns squirrel SelectBuilder built from provided opts Deprecated: use github.com/n-r-w/squirrel

func WithIn

func WithIn[T any](sqlName string, values []T) option

WithIn adds an IN condition for sqlName with values

func WithInConds

func WithInConds(conds ...inCond) option

WithInConds adds IN conditions. Useful in cases where you need to customize the created InCond condition

func WithOrders

func WithOrders(aliases map[int]string, orders ...OrderCond) option

WithOrders adds sorting conditions (orders). Aliases for mapping orderID from OrderCond and sqlName are passed in aliases parameter. Duplicate sort conditions are ignored

func WithPKField

func WithPKField(pkfield string) option

WithPKField specifies the name for PK. Used in cases where PK name differs from default "id". Can specify a composite key in the format: (field1, field2)

func WithPaginator

func WithPaginator(paginator Paginator) option

WithPaginator adds pagination based on Paginator. If a service paginator is provided, pagination will be performed by the last PK value with condition pkField > lastID If a frontend paginator is provided, pagination will be performed by limit and offset. Panics when attempting to add paginator again

func WithSearch

func WithSearch(search string, fields ...string) option

WithSearch adds search condition for all provided fields

func WithoutOrder

func WithoutOrder() option

WithoutOrder forcibly disables sorting

Types

type OrderCond

type OrderCond struct {
	Type OrderType
	// contains filtered or unexported fields
}

OrderCond sort condition

func NewOrder

func NewOrder(orderID int, t OrderType) *OrderCond

NewOrder returns an object for sorting data by orderID with sort type t

type OrderType

type OrderType int

OrderType represents sort type

func (OrderType) String

func (o OrderType) String() string

type Paginator

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

Paginator Data pagination

func NewFrontPaginator

func NewFrontPaginator(limit uint32, page uint64) *Paginator

NewFrontPaginator returns a frontend type paginator

func NewServicePaginator

func NewServicePaginator(limit uint32, lastID uint64) *Paginator

NewServicePaginator returns a service type paginator

func (*Paginator) IsFront

func (p *Paginator) IsFront() bool

IsFront returns true if paginator type is frontend

func (*Paginator) IsService

func (p *Paginator) IsService() bool

IsService returns true if paginator type is service

Jump to

Keyboard shortcuts

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