filters

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

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 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{},
) (f *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, schemaName string, values ...interface{}) (*FilterField, error)

NewStringFilter creates the filter field based on the provided 'filter', 'schemaName' and 'values'. The filter should not contain the values. If the 'schemaName' is not provided the defaultSchema for given controller would be taken. Example:

  • 'fitler': "filter[collection][fieldName][operator]"
  • 'schema': "schemaName"
  • '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, schemaName string, values ...interface{}) (*FilterField, error)

NewStringFilterWithForeignKey creates the filter field based on the provided filter, schemaName and values. The filter should not contain the values. If the 'schemaName' is not provided the defaultSchema for given controller would be taken. 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) 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 Operator

type Operator filters.Operator

Operator is a query filter operator.

func NewOperator

func NewOperator(queryRaw, name string) *Operator

NewOperator creates new operator with the 'name' and 'queryRaw' provided in the arguments.

func (*Operator) IsStandard

func (o *Operator) IsStandard() bool

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.

Jump to

Keyboard shortcuts

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