Documentation ¶
Index ¶
- Constants
- Variables
- func Generic(oo ...filterOpt) *filter
- func WithConstraint(k string, v any) filterOpt
- func WithConstraints(c map[string][]any) filterOpt
- func WithCursor(p *PagingCursor) filterOpt
- func WithExpression(e string) filterOpt
- func WithExpressionParsed(e *ql.ASTNode) filterOpt
- func WithLimit(l uint) filterOpt
- func WithMetaConstraints(mc map[string]any) filterOpt
- func WithOrderBy(o SortExprSet) filterOpt
- func WithStateConstraint(k string, s State) filterOpt
- func WithStateConstraints(sc map[string]State) filterOpt
- type Filter
- type Page
- type Paging
- type PagingCursor
- func (p *PagingCursor) Decode(cursor string) error
- func (p *PagingCursor) Desc() []bool
- func (p *PagingCursor) Encode() string
- func (p *PagingCursor) IsLThen() bool
- func (p *PagingCursor) IsROrder() bool
- func (p *PagingCursor) KK() [][]string
- func (p *PagingCursor) Keys() []string
- func (p *PagingCursor) MarshalJSON() ([]byte, error)
- func (p *PagingCursor) Modifiers() []string
- func (p *PagingCursor) Set(k string, v interface{}, d bool)
- func (p *PagingCursor) SetModifier(k string, v interface{}, d bool, m string, kk ...string)
- func (p *PagingCursor) Sort(sort SortExprSet) (SortExprSet, error)
- func (p *PagingCursor) String() string
- func (cur *PagingCursor) ToAST(identLookup func(i string) (string, error), ...) (out *ql.ASTNode, err error)
- func (p *PagingCursor) UnmarshalJSON(in []byte) error
- func (p *PagingCursor) Values() []interface{}
- func (p *PagingCursor) Walk(fn func(string, interface{}, bool))
- type SortExpr
- type SortExprSet
- func (set SortExprSet) Clone() (out SortExprSet)
- func (set SortExprSet) Columns() []string
- func (set SortExprSet) Get(col string) *SortExpr
- func (set SortExprSet) LastDescending() bool
- func (set SortExprSet) MarshalJSON() ([]byte, error)
- func (set SortExprSet) Reverse()
- func (set SortExprSet) Reversed() bool
- func (set *SortExprSet) Set(in string) error
- func (set SortExprSet) String() string
- func (set *SortExprSet) UnmarshalJSON(in []byte) error
- func (set SortExprSet) Validate(cc ...string) error
- type Sorting
- type State
Constants ¶
const (
COALESCE = "coalesce"
)
Variables ¶
var (
ErrIncompatibleSort = fmt.Errorf("sort incompatible with cursor; send empty sort")
)
Functions ¶
func WithConstraint ¶
WithConstraint sets single constraint to filter
func WithConstraints ¶
WithConstraints set multiple constraints to filter
func WithExpression ¶
func WithExpression(e string) filterOpt
WithExpression sets expression to filter
func WithExpressionParsed ¶
WithExpressionParsed sets parsed expression to filter
func WithMetaConstraints ¶
WithMetaConstraints sets multiple state constraints to filter
func WithStateConstraint ¶
WithStateConstraint sets single state constraint to filter
func WithStateConstraints ¶
WithStateConstraints sets multiple state constraints to filter
Types ¶
type Filter ¶
type Filter interface { // Constraints returns map of attribute idents and values // used for structured filtering ({a1: [v1], a2: [v2, v3]} => "a1 = v1 AND a2 = (v2,v4)") Constraints() map[string][]any // StateConstraints returns map of attribute idents and states // used for structured filtering ({a1: s1, a2: s2} => "a1 = s1 AND a2 = s2") StateConstraints() map[string]State // MetaConstraints returns meta constraints MetaConstraints() map[string]any // Expression returns string, parseable by ql package Expression() string // OrderBy one or more fields OrderBy() SortExprSet // Limit amount of returned results Limit() uint // Cursor from the last fetch Cursor() *PagingCursor }
type Page ¶
type Page struct { Page uint `json:"page"` Count uint `json:"items"` Cursor *PagingCursor `json:"cursor"` }
type Paging ¶
type Paging struct { // How many items per fetch do we want Limit uint `json:"limit,omitempty"` // Opaque pointer to 1st item on page // read-only PageCursor *PagingCursor `json:"cursor,omitempty"` // Opaque cursor that points to the first item on the next page // read-only NextPage *PagingCursor `json:"nextPage,omitempty"` // Opaque cursor that points to the first item on the previous page // value of {cursor} will be copied here // read-only PrevPage *PagingCursor `json:"prevPage,omitempty"` IncTotal bool `json:"incTotal,omitempty"` Total uint `json:"total,omitempty"` }
Paging is a helper struct that should be embedded in filter types to help with the paging
type PagingCursor ¶
type PagingCursor struct { // sort in desc order ROrder bool // use < op instead of > LThen bool // contains filtered or unexported fields }
func PagingCursorFrom ¶
func PagingCursorFrom(ss SortExprSet, v valueGetter, primaries ...string) (_ *PagingCursor, err error)
PagingCursorFrom constructs a new paging cursor for the given valueGetter
func (*PagingCursor) Decode ¶
func (p *PagingCursor) Decode(cursor string) error
func (*PagingCursor) Desc ¶
func (p *PagingCursor) Desc() []bool
func (*PagingCursor) Encode ¶
func (p *PagingCursor) Encode() string
func (*PagingCursor) IsLThen ¶
func (p *PagingCursor) IsLThen() bool
func (*PagingCursor) IsROrder ¶
func (p *PagingCursor) IsROrder() bool
func (*PagingCursor) KK ¶
func (p *PagingCursor) KK() [][]string
func (*PagingCursor) Keys ¶
func (p *PagingCursor) Keys() []string
func (*PagingCursor) MarshalJSON ¶
func (p *PagingCursor) MarshalJSON() ([]byte, error)
MarshalJSON serializes cursor struct as JSON and encodes it as base64 + adds quotes to be treated as JSON string
func (*PagingCursor) Modifiers ¶
func (p *PagingCursor) Modifiers() []string
func (*PagingCursor) Set ¶
func (p *PagingCursor) Set(k string, v interface{}, d bool)
func (*PagingCursor) SetModifier ¶
func (p *PagingCursor) SetModifier(k string, v interface{}, d bool, m string, kk ...string)
func (*PagingCursor) Sort ¶
func (p *PagingCursor) Sort(sort SortExprSet) (SortExprSet, error)
Sort returns:
- sort if cursor is nil
- sort from cursor when sort is empty
- sort from cursor when sort is compatible with cursor
- error if sort & cursor are incompatible
func (*PagingCursor) String ¶
func (p *PagingCursor) String() string
Stirng to implement Stringer and to get human-readable representation of the cursor
func (*PagingCursor) ToAST ¶
func (cur *PagingCursor) ToAST(identLookup func(i string) (string, error), castFn func(i string, val any) (expr.TypedValue, error)) (out *ql.ASTNode, err error)
ToAST converts the given PagingCursor to a corresponding AST tree
The method should be used as the base for generating filtering expressions when working with databases, DAL reports, ...
@todo discuss this one
func (*PagingCursor) UnmarshalJSON ¶
func (p *PagingCursor) UnmarshalJSON(in []byte) error
func (*PagingCursor) Values ¶
func (p *PagingCursor) Values() []interface{}
func (*PagingCursor) Walk ¶
func (p *PagingCursor) Walk(fn func(string, interface{}, bool))
type SortExprSet ¶
type SortExprSet []*SortExpr
func (SortExprSet) Clone ¶
func (set SortExprSet) Clone() (out SortExprSet)
Clone returns cloned sort expression set
func (SortExprSet) Columns ¶
func (set SortExprSet) Columns() []string
Reverse reverses direction on each expression
func (SortExprSet) Get ¶
func (set SortExprSet) Get(col string) *SortExpr
Get returns sort expression from set if exists
func (SortExprSet) LastDescending ¶
func (set SortExprSet) LastDescending() bool
LastDescending returns true if last sort expr/col is descending
func (SortExprSet) MarshalJSON ¶
func (set SortExprSet) MarshalJSON() ([]byte, error)
UnmarshalJSON parses sort expression when passed inside JSON
func (SortExprSet) Reverse ¶
func (set SortExprSet) Reverse()
Reverse reverses direction on each expression
func (SortExprSet) Reversed ¶
func (set SortExprSet) Reversed() bool
Sorting is revered if 1st expr has desc direction
func (*SortExprSet) Set ¶
func (set *SortExprSet) Set(in string) error
UnmarshalJSON parses stringified sort expression when passed inside JSON
func (SortExprSet) String ¶
func (set SortExprSet) String() string
func (*SortExprSet) UnmarshalJSON ¶
func (set *SortExprSet) UnmarshalJSON(in []byte) error
UnmarshalJSON parses sort expression when passed inside JSON
func (SortExprSet) Validate ¶
func (set SortExprSet) Validate(cc ...string) error
Validate returns error if any of the SortExpr columns is missing from the given list
type Sorting ¶
type Sorting struct {
Sort SortExprSet `json:"sort,omitempty"`
}
Sort is a helper struct that should be embedded in filter types to help with the sorting
func NewSorting ¶
func (*Sorting) OrderBy ¶
func (s *Sorting) OrderBy() SortExprSet
type State ¶
type State uint
State for filtering by state, for example: include, exclude or return only deleted values