filters

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// logical filters
	AnnotationOperatorEqual        = "$eq"
	AnnotationOperatorIn           = "$in"
	AnnotationOperatorNotEqual     = "$ne"
	AnnotationOperatorNotIn        = "$notin"
	AnnotationOperatorGreaterThan  = "$gt"
	AnnotationOperatorGreaterEqual = "$ge"
	AnnotationOperatorLessThan     = "$lt"
	AnnotationOperatorLessEqual    = "$le"
	AnnotationOperatorIsNull       = "$isnull"
	AnnotationOperatorNotNull      = "$notnull"
	AnnotationOperatorExists       = "$exists"
	AnnotationOperatorNotExists    = "$notexists"
	AnnotationOperatorContains     = "$contains"
	AnnotationOperatorStartsWith   = "$startswith"
	AnnotationOperatorEndsWith     = "$endswith"
	AnnotationOperatorStDWithin    = "$st_dwithin"
)

Operators

Variables

This section is empty.

Functions

func AddNestedField

func AddNestedField(f, nested *FilterField)

AddNestedField adds nested filterfield for the filter 'f'

func FilterAppendValues

func FilterAppendValues(f *FilterField, values ...*OpValuePair)

FilterAppendvalues adds the values to the given filter field

Types

type FilterField

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

FilterField is a field that contains information about filters

func CopyFilter

func CopyFilter(f *FilterField) *FilterField

CopyFilter copies given FilterField with it's values

func GetOrCreateNestedFilter

func GetOrCreateNestedFilter(f *FilterField, field interface{}) *FilterField

GetOrCreateNestedFilter gets the filter field for given field If the field is a key returns the filter by key

func NestedFields

func NestedFields(f *FilterField) []*FilterField

func NewFilter

func NewFilter(s *models.StructField, values ...*OpValuePair) *FilterField

NewFilter creates the filterField for given stuct field and values

func (*FilterField) AddNestedField

func (f *FilterField) AddNestedField(nested *FilterField)

AddNestedField adds the nested field value

func (*FilterField) AddValues

func (f *FilterField) AddValues(values ...*OpValuePair)

AddValues adds provided values to the filter values

func (*FilterField) Key

func (f *FilterField) Key() string

Key returns the filter key if set

func (*FilterField) NestedFields

func (f *FilterField) NestedFields() []*FilterField

NestedFields returns nested fields for given filter

func (*FilterField) Raw

func (f *FilterField) Raw() string

ToRaw returns raw string filter

func (*FilterField) SetValues

func (f *FilterField) SetValues(
	values []string,
	op *Operator,
	sup *i18n.Support,
) (errObj *aerrors.ApiError)

SetValues sets the filter values for provided field, it's operator and possible i18n Support

func (*FilterField) StructField

func (f *FilterField) StructField() *models.StructField

StructField returns the filter's StructField

func (*FilterField) Values

func (f *FilterField) Values() []*OpValuePair

Values return filter values

type OpValuePair

type OpValuePair struct {
	Values []interface{}
	// contains filtered or unexported fields
}

OpValuePair are the values used within the provided FilterField It contains the Values which is a slice of provided values for given 'Operator'

func CopyOpValuePair

func CopyOpValuePair(o *OpValuePair) *OpValuePair

CopyOpValuePair copies operator value pair

func FilterOpValuePairs

func FilterOpValuePairs(f *FilterField) []*OpValuePair

FilterOpValuePairs returns the values of the provided filter field.

func NewOpValuePair

func NewOpValuePair(o *Operator, values ...interface{}) *OpValuePair

NewOpValuePair creates new operator value pair

func (*OpValuePair) Operator

func (o *OpValuePair) Operator() *Operator

Operator gets the operator for OpValuePair

func (*OpValuePair) SetOperator

func (o *OpValuePair) SetOperator(op *Operator)

SetOperator sets the operator for given opvalue pair

type Operator

type Operator struct {
	// Id is the filter operator id used for comparing the operator type
	Id uint16

	// Raw is the raw value of the current operator
	Raw string

	// Name is the human readable filter operator string value
	Name string
}

Operator is the operator used while filtering the query

var (
	// Logical Operators
	OpEqual        *Operator = &Operator{Raw: AnnotationOperatorEqual, Name: "Equal"}
	OpIn           *Operator = &Operator{Raw: AnnotationOperatorIn, Name: "In"}
	OpNotEqual     *Operator = &Operator{Raw: AnnotationOperatorNotEqual, Name: "NotEqual"}
	OpNotIn        *Operator = &Operator{Raw: AnnotationOperatorNotIn, Name: "NotIn"}
	OpGreaterThan  *Operator = &Operator{Raw: AnnotationOperatorGreaterThan, Name: "GreaterThan"}
	OpGreaterEqual *Operator = &Operator{Raw: AnnotationOperatorGreaterEqual, Name: "GreaterThanOrEqualTo"}
	OpLessThan     *Operator = &Operator{Raw: AnnotationOperatorLessThan, Name: "LessThan"}
	OpLessEqual    *Operator = &Operator{Raw: AnnotationOperatorLessEqual, Name: "LessThanOrEqualTo"}

	// Strings Only operators
	OpContains   = &Operator{Raw: AnnotationOperatorContains, Name: "Contains"}
	OpStartsWith = &Operator{Raw: AnnotationOperatorStartsWith, Name: "StartsWith"}
	OpEndsWith   = &Operator{Raw: AnnotationOperatorEndsWith, Name: "EndsWith"}

	OpIsNull    *Operator = &Operator{Raw: AnnotationOperatorIsNull, Name: "IsNull"}
	OpNotNull   *Operator = &Operator{Raw: AnnotationOperatorNotNull, Name: "NotNull"}
	OpExists    *Operator = &Operator{Raw: AnnotationOperatorExists, Name: "Exists"}
	OpNotExists *Operator = &Operator{Raw: AnnotationOperatorNotExists, Name: "NotExists"}
)

func (Operator) IsStandard

func (f Operator) IsStandard() bool

IsStandard checks if the operator is standard

func (Operator) String

func (f Operator) String() string

String implements Stringer interface

type OperatorContainer

type OperatorContainer struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

OperatorContainer is the container for the filter operators It registers new operators and checks if no operator with provided Raw value already exists inside.

var Operators *OperatorContainer = NewOpContainer()

Operators contains all the registered operators

func NewOpContainer

func NewOpContainer() *OperatorContainer

NewOpContainer creates new container operator

func (*OperatorContainer) Get

func (c *OperatorContainer) Get(raw string) (*Operator, bool)

Get gets the operator on the base of the raw value

func (*OperatorContainer) GetByName

func (c *OperatorContainer) GetByName(name string) (*Operator, bool)

GetByName gets the operator by the name

func (*OperatorContainer) RegisterOperator

func (c *OperatorContainer) RegisterOperator(op *Operator) error

RegisterOperator registers single operator

func (*OperatorContainer) RegisterOperators

func (c *OperatorContainer) RegisterOperators(ops ...*Operator) error

RegisterOperators registers multiple operators

Jump to

Keyboard shortcuts

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