filter

package
v2.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2018 License: LGPL-2.1 Imports: 11 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllValue = `all`
View Source
var CriteriaSeparator = `/`
View Source
var DefaultIdentityField = `id`
View Source
var DefaultNormalizerFunc = func(in string) string {
	in = strings.ToLower(in)
	return rxCharFilter.ReplaceAllString(in, ``)
}
View Source
var FieldLengthDelimiter = `#`
View Source
var FieldTermSeparator = `/`
View Source
var ModifierDelimiter = `:`
View Source
var QueryUnescapeValues = false
View Source
var SortAscending = `+`
View Source
var SortDescending = `-`
View Source
var ValueSeparator = `|`

Functions

func IsExactMatchOperator

func IsExactMatchOperator(operator string) bool

func IsInvertingOperator

func IsInvertingOperator(operator string) bool

func Render

func Render(generator IGenerator, collectionName string, filter *Filter) ([]byte, error)

func SplitModifierToken

func SplitModifierToken(in string) (string, string)

Types

type Aggregate

type Aggregate struct {
	Aggregation Aggregation
	Field       string
}

type Aggregation

type Aggregation int
const (
	First Aggregation = iota
	Last
	Minimum
	Maximum
	Sum
	Average
	Count
)

type ConjunctionType

type ConjunctionType string
const (
	AndConjunction ConjunctionType = ``
	OrConjunction                  = `or`
)

type Criterion

type Criterion struct {
	Type        dal.Type      `json:"type,omitempty"`
	Length      int           `json:"length,omitempty"`
	Field       string        `json:"field"`
	Operator    string        `json:"operator,omitempty"`
	Values      []interface{} `json:"values"`
	Aggregation Aggregation   `json:"aggregation,omitempty"`
}

func (*Criterion) String

func (self *Criterion) String() string

type Filter

type Filter struct {
	Spec          string
	MatchAll      bool
	Offset        int
	Limit         int
	Criteria      []Criterion
	Sort          []string
	Fields        []string
	Options       map[string]interface{}
	Paginate      bool
	IdentityField string
	Normalizer    NormalizerFunc
	Conjunction   ConjunctionType
}

func All

func All() *Filter

func Copy

func Copy(other *Filter) Filter

func FromMap

func FromMap(in map[string]interface{}) (*Filter, error)

func MakeFilter

func MakeFilter(specs ...string) Filter

func MustParse

func MustParse(spec string) *Filter

func New

func New() *Filter

func Null

func Null() *Filter

func Parse

func Parse(spec string) (*Filter, error)

Filter syntax definition

func (*Filter) AddCriteria

func (self *Filter) AddCriteria(criteria ...Criterion) *Filter

func (*Filter) ApplyOptions

func (self *Filter) ApplyOptions(in interface{}) error

func (*Filter) BoundedBy

func (self *Filter) BoundedBy(limit int, offset int) *Filter

func (*Filter) CriteriaFields

func (self *Filter) CriteriaFields() []string

func (*Filter) GetFirstValue

func (self *Filter) GetFirstValue() (interface{}, bool)

func (*Filter) GetIdentityValue

func (self *Filter) GetIdentityValue() (interface{}, bool)

func (*Filter) GetSort

func (self *Filter) GetSort() []SortBy

func (*Filter) GetValues

func (self *Filter) GetValues(field string) ([]interface{}, bool)

func (*Filter) IdOnly

func (self *Filter) IdOnly() bool

func (*Filter) IsMatchAll

func (self *Filter) IsMatchAll() bool

func (*Filter) MatchesRecord

func (self *Filter) MatchesRecord(record *dal.Record) bool

func (*Filter) NewFromMap

func (self *Filter) NewFromMap(in map[string]interface{}) (*Filter, error)

func (*Filter) NewFromSpec

func (self *Filter) NewFromSpec(specs ...string) (*Filter, error)

func (*Filter) SortBy

func (self *Filter) SortBy(fields ...string) *Filter

func (*Filter) String

func (self *Filter) String() string

func (*Filter) WithFields

func (self *Filter) WithFields(fields ...string) *Filter

type Generator

type Generator struct {
	IGenerator
	// contains filtered or unexported fields
}

func (*Generator) Finalize

func (self *Generator) Finalize(_ *Filter) error

func (*Generator) Payload

func (self *Generator) Payload() []byte

func (*Generator) Push

func (self *Generator) Push(data []byte)

func (*Generator) Reset

func (self *Generator) Reset()

func (*Generator) Set

func (self *Generator) Set(data []byte)

type IGenerator

type IGenerator interface {
	Initialize(string) error
	Finalize(*Filter) error
	Push([]byte)
	Set([]byte)
	Payload() []byte
	WithCriterion(Criterion) error
	OrCriterion(Criterion) error
	WithField(string) error
	GroupByField(string) error
	AggregateByField(Aggregation, string) error
	SetOption(string, interface{}) error
	GetValues() []interface{}
	Reset()
}

type NormalizerFunc

type NormalizerFunc func(in string) string // {}

type SortBy

type SortBy struct {
	Field      string
	Descending bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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