filter

package
v0.21.6 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: Apache-2.0 Imports: 5 Imported by: 13

Documentation

Index

Constants

View Source
const (
	// ParamFilter is the filter query parameter used as the key in the url values.
	ParamFilter = "filter"
)

Variables

View Source
var (
	// ErrFilter is the minor error classification related to the filters.
	ErrFilter = errors.New("filter")
	// ErrFilterField is the error classification for the filter fields.
	ErrFilterField = errors.Wrap(ErrFilter, "field")
	// ErrFilterFormat is the error classification for the filter format.
	ErrFilterFormat = errors.Wrap(ErrFilter, "format")
	// ErrFilterCollection is the error classification for the filter collection.
	ErrFilterCollection = errors.Wrap(ErrFilter, "collection")
	// ErrFilterValues is the error classification for the filter values.
	ErrFilterValues = errors.Wrap(ErrFilter, "values")
)
View Source
var (
	OpEqual        = &Operator{Value: "=", URLAlias: "$eq", Name: "Equal", Aliases: []string{"=="}}
	OpIn           = &Operator{Value: "in", URLAlias: "$in", Name: "In"}
	OpNotEqual     = &Operator{Value: "!=", URLAlias: "$ne", Name: "NotEqual", Aliases: []string{"<>"}}
	OpNotIn        = &Operator{Value: "not in", URLAlias: "$not_in", Name: "NotIn"}
	OpGreaterThan  = &Operator{Value: ">", URLAlias: "$gt", Name: "GreaterThan"}
	OpGreaterEqual = &Operator{Value: ">=", URLAlias: "$ge", Name: "GreaterThanOrEqualTo"}
	OpLessThan     = &Operator{Value: "<", URLAlias: "$lt", Name: "LessThan"}
	OpLessEqual    = &Operator{Value: "<=", URLAlias: "$le", Name: "LessThanOrEqualTo"}
)

Logical Operators

View Source
var (
	OpContains   = &Operator{Value: "contains", URLAlias: "$contains", Name: "Contains"}
	OpStartsWith = &Operator{Value: "starts with", URLAlias: "$starts_with", Name: "StartsWith"}
	OpEndsWith   = &Operator{Value: "ends with", URLAlias: "$ends_with", Name: "EndsWith"}
)

Strings Only operators.

View Source
var (
	OpIsNull  = &Operator{Value: "is null", URLAlias: "$is_null", Name: "IsNull"}
	OpNotNull = &Operator{Value: "not null", URLAlias: "$not_null", Name: "NotNull"}
)

Null and Existence operators.

View Source
var Operators = newOpContainer()

Operators is the container that stores all query filter operators.

Functions

func RegisterMultipleOperators

func RegisterMultipleOperators(operators ...*Operator) error

RegisterMultipleOperators registers multiple operators at once

func RegisterOperator

func RegisterOperator(o *Operator) error

RegisterOperator registers the operator in the provided container

Types

type Filter

type Filter interface {
	Copy() Filter
	String() string
}

Filter is the interface used a filter for the queries.

func NewFilter

func NewFilter(model *mapping.ModelStruct, filter string, values ...interface{}) (Filter, error)

NewFilter creates new filterField for the default controller, 'model', 'filter' query and 'values'. The 'filter' should be of form:

  • Simple Operator 'ID IN', 'Name CONTAINS', 'id in', 'name contains'
  • Relationship.Simple Operator 'Car.UserID IN', 'Car.Doors ==', 'car.user_id >=",

The field might be a Golang model field name or the neuron name.

func Or

func Or(filters ...Simple) Filter

Or creates a logical 'OR' group filter. Currently only simple filter is allowed to be part of OrGroupFilter

type Filters

type Filters []Filter

Filters is the wrapper over the slice of filter fields.

func (Filters) String

func (f Filters) String() string

String implements fmt.Stringer interface.

type Operator

type Operator struct {
	// ID is the filter operator id used for comparing the operator type.
	ID uint16
	// Models is the operator query value
	Value string
	// Name is the human readable filter operator name.
	Name string
	// URLAlias is the alias value for the url parsable value operator.
	URLAlias string
	// Aliases is the alias for the operator raw value.
	Aliases []string
}

Operator is the operator used for filtering the query.

func (*Operator) IsBasic

func (f *Operator) IsBasic() bool

IsBasic checks if the operator is 'OpEqual' or OpNotEqual.

func (*Operator) IsRangeable

func (f *Operator) IsRangeable() bool

IsRangeable checks if the operator allows to have value ranges.

func (*Operator) IsStandard

func (f *Operator) IsStandard() bool

IsStandard checks if the operator is standard.

func (*Operator) IsStringOnly

func (f *Operator) IsStringOnly() bool

IsStringOnly checks if the operator is 'string only'.

func (*Operator) String

func (f *Operator) String() string

String implements Stringer interface.

type OrGroup

type OrGroup []Simple

OrGroup is the filter that allows to make a logical OR query.

func (OrGroup) Copy

func (o OrGroup) Copy() Filter

Copy implements Filter interface.

func (OrGroup) String

func (o OrGroup) String() string

Stringer implements fmt.Stringer interface.

type Relation

type Relation struct {
	StructField *mapping.StructField
	// Nested are the relationship fields filters.
	Nested []Filter
}

Relation is the relationship filter field.

func NewRelation

func NewRelation(relation *mapping.StructField, relFilters ...Filter) Relation

NewRelation creates new relationship filter for the 'relation' StructField. It adds all the nested relation sub filters 'relFilters'.

func (Relation) Copy

func (r Relation) Copy() Filter

Copy implements Filter interface.

func (Relation) String

func (r Relation) String() string

String implements fmt.Stringer interface.

type Simple

type Simple struct {
	StructField *mapping.StructField
	Operator    *Operator
	Values      []interface{}
}

Simple is a struct that keeps information about given query filters. It is based on the mapping.StructField.

func New

func New(field *mapping.StructField, op *Operator, values ...interface{}) Simple

New creates new filterField for given 'field', operator and 'values'.

func (Simple) Copy

func (f Simple) Copy() Filter

Copy returns the copy of the filter field.

func (Simple) String

func (f Simple) String() string

String implements fmt.Stringer interface.

Jump to

Keyboard shortcuts

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