Documentation
¶
Index ¶
Constants ¶
const (
// ParamFilter is the filter query parameter used as the key in the url values.
ParamFilter = "filter"
)
Variables ¶
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") )
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
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.
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.
var Operators = newOpContainer()
Operators is the container that stores all query filter operators.
Functions ¶
func RegisterMultipleOperators ¶
RegisterMultipleOperators registers multiple operators at once
func RegisterOperator ¶
RegisterOperator registers the operator in the provided container
Types ¶
type Filter ¶
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.
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) IsRangeable ¶
IsRangeable checks if the operator allows to have value ranges.
func (*Operator) IsStandard ¶
IsStandard checks if the operator is standard.
func (*Operator) IsStringOnly ¶
IsStringOnly checks if the operator is 'string only'.
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'.
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.