Documentation
¶
Overview ¶
Package filters defines the filter field structure, it's methods and create functions. It is used by the queries to filter their results.
Index ¶
- Constants
- Variables
- func RegisterMultipleOperators(operators ...*Operator) error
- func RegisterOperator(o *Operator) error
- func SplitBracketParameter(bracketed string) (values []string, err error)
- type FilterField
- func NewFilter(field *mapping.StructField, op *Operator, values ...interface{}) *FilterField
- func NewRelationshipFilter(relation *mapping.StructField, relFilters ...*FilterField) *FilterField
- func NewStringFilter(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
- func NewStringFilterWithForeignKey(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
- type Filters
- type Operator
- type OperatorValuePair
- type QueryValuer
Constants ¶
const ( // QueryParamLanguage is the language query parameter used in the url values. QueryParamLanguage = "lang" // QueryParamFilter is the filter query parameter used as the key in the url values. QueryParamFilter = "filter" )
Variables ¶
var ( // OpEqual is the standard filter operator. OpEqual = (*Operator)(filters.OpEqual) // OpIn is the standard filter operator. OpIn = (*Operator)(filters.OpIn) // OpNotEqual is the standard filter operator. OpNotEqual = (*Operator)(filters.OpNotEqual) // OpNotIn is the standard filter operator. OpNotIn = (*Operator)(filters.OpNotIn) // OpGreaterThan is the standard filter operator. OpGreaterThan = (*Operator)(filters.OpGreaterThan) // OpGreaterEqual is the standard filter operator. OpGreaterEqual = (*Operator)(filters.OpGreaterEqual) // OpLessThan is the standard filter operator. OpLessThan = (*Operator)(filters.OpLessThan) // OpLessEqual is the standard filter operator. OpLessEqual = (*Operator)(filters.OpLessEqual) // OpContains is the standard filter operator. OpContains = (*Operator)(filters.OpContains) // OpStartsWith is the standard filter operator. OpStartsWith = (*Operator)(filters.OpStartsWith) // OpEndsWith is the standard filter operator. OpEndsWith = (*Operator)(filters.OpEndsWith) // OpIsNull is the standard filter operator. OpIsNull = (*Operator)(filters.OpIsNull) // OpNotNull is the standard filter operator. OpNotNull = (*Operator)(filters.OpNotNull) // OpExists is the standard filter operator. OpExists = (*Operator)(filters.OpExists) // OpNotExists is the standard filter operator. OpNotExists = (*Operator)(filters.OpNotExists) )
Functions ¶
func RegisterMultipleOperators ¶
RegisterMultipleOperators registers multiple operators at once
func RegisterOperator ¶
RegisterOperator registers the operator in the provided container
func SplitBracketParameter ¶ added in v0.4.0
SplitBracketParameter splits the parameters within the '[' and ']' brackets.
Types ¶
type FilterField ¶
type FilterField filters.FilterField
FilterField is a struct that keeps information about given query filters. It is based on the mapping.StructField.
func NewFilter ¶
func NewFilter(field *mapping.StructField, op *Operator, values ...interface{}) *FilterField
NewFilter creates new filterfield for given field, operator and values.
func NewRelationshipFilter ¶
func NewRelationshipFilter(relation *mapping.StructField, relFilters ...*FilterField) *FilterField
NewRelationshipFilter creates new relationship filter for the 'relation' StructField. It adds all the nested relation subfilters 'relFilters'.
func NewStringFilter ¶
func NewStringFilter(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
NewStringFilter creates the filter field based on the provided 'filter' and 'values'. Example:
- 'fitler': "filter[collection][fieldName][operator]"
- 'values': 5, 13
This function doesn't allow to filter over foreign keys.
func NewStringFilterWithForeignKey ¶ added in v0.2.1
func NewStringFilterWithForeignKey(c *controller.Controller, filter string, values ...interface{}) (*FilterField, error)
NewStringFilterWithForeignKey creates the filter field based on the provided filter, schemaName and values. Example:
- 'fitler': "filter[collection][fieldName][operator]"
- 'schema': "schemaName"
- 'values': 5, 13
This function allow to filter over the foreign key fields.
func (*FilterField) FormatQuery ¶
func (f *FilterField) FormatQuery(q ...url.Values) url.Values
FormatQuery formats the filter field into url.Values. If the 'q' optional parameter is set, then the function would add the values into the provided argument 'q' url.Values. Otherwise it creates new url.Values. Returns updated (new) url.Values.
func (*FilterField) NestedFilters ¶
func (f *FilterField) NestedFilters() []*FilterField
NestedFilters returns the nested filters for given filter fields. Nested filters are the filters used for relationship or composite attribute filters.
func (*FilterField) String ¶ added in v0.5.1
func (f *FilterField) String() string
func (*FilterField) StructField ¶
func (f *FilterField) StructField() *mapping.StructField
StructField returns the structfield related with the filter field.
func (*FilterField) Values ¶
func (f *FilterField) Values() (values []*OperatorValuePair)
Values returns OperatorValuesPair.
type Filters ¶ added in v0.5.1
type Filters []*FilterField
Filters is the wrapper over the slice of filter fields.
type Operator ¶
Operator is a query filter operator.
func NewOperator ¶
NewOperator creates new operator with the 'name' and 'queryRaw' provided in the arguments.
func (*Operator) IsStandard ¶
IsStandard defines if the operator is a standard filter operator.
type OperatorValuePair ¶
type OperatorValuePair filters.OpValuePair
OperatorValuePair is a struct that holds the Operator information with the related filter values.
func (*OperatorValuePair) Operator ¶
func (o *OperatorValuePair) Operator() *Operator
Operator returns the operator.
func (*OperatorValuePair) SetOperator ¶
func (o *OperatorValuePair) SetOperator(op *Operator)
SetOperator sets the operator in the operator value pair.
type QueryValuer ¶
type QueryValuer interface {
QueryValue(sField *mapping.StructField) string
}
QueryValuer is the interface that allows parsing the structures into golang filters string values.