Documentation
¶
Overview ¶
Package builder generates dynamic expressions based on a set of url.Values and a map of allowed fields. It supports several different data types, along with a simple list of operators that can be applied to each predicate.
Index ¶
- Constants
- type Builder
- func (b Builder) Bool(name string, options ...FieldOption) Builder
- func (b Builder) Evaluate(values url.Values) exp.Expression
- func (b Builder) EvaluateAll(values url.Values) (exp.Expression, error)
- func (b Builder) EvaluateField(field Field, values []string) exp.Expression
- func (b Builder) HasURLParams(values url.Values) bool
- func (b Builder) Int(name string, options ...FieldOption) Builder
- func (b Builder) Int64(name string, options ...FieldOption) Builder
- func (b Builder) ObjectID(name string, options ...FieldOption) Builder
- func (b Builder) Polygon(name string, options ...FieldOption) Builder
- func (b Builder) String(name string, options ...FieldOption) Builder
- func (b Builder) Time(name string, options ...FieldOption) Builder
- type Field
- type FieldOption
- type Filter
Constants ¶
const DataTypeBool = "BOOL"
DataTypeBool represents a boolean parameter
const DataTypeInt = "INT"
DataTypeInt represents an integer parameter
const DataTypeInt64 = "INT64"
DataTypeInt64 represents a 64-bit integer parameter
const DataTypeObjectID = "OBJECTID"
DataTypeObjectID represents a mongodb "ObjectId" parameter (24-byte hex string)
const DataTypePolygon = "POLYGON"
DataTypePolygon represents a GeoJSON polygon
const DataTypeString = "STRING"
DataTypeString represents a string parameter
const DataTypeTime = "TIME"
DataTypeTime represents a time.Time parameter
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
Builder maps URL parameter names to the Fields that describe how to turn their values into an expression.
func (Builder) Bool ¶
func (b Builder) Bool(name string, options ...FieldOption) Builder
Bool adds a boolean-based parameter to the expression Builder
func (Builder) Evaluate ¶
func (b Builder) Evaluate(values url.Values) exp.Expression
Evaluate returns an Expression based on the specific url.Values provided
func (Builder) EvaluateAll ¶ added in v0.5.0
EvaluateAll is like Evaluate, but every field defined in the Builder must be present and non-empty in the URL values. It returns an error if any is missing.
func (Builder) EvaluateField ¶ added in v0.7.0
func (b Builder) EvaluateField(field Field, values []string) exp.Expression
EvaluateField converts the raw URL values for a single field into an expression, parsing each value according to the field's data type.
func (Builder) HasURLParams ¶ added in v0.5.0
HasURLParams returns TRUE if the URL contains any parameters that match the Builder. It does not test the validity of those values.
func (Builder) Int ¶
func (b Builder) Int(name string, options ...FieldOption) Builder
Int adds an integer-based parameter to the expression Builder
func (Builder) Int64 ¶ added in v0.7.0
func (b Builder) Int64(name string, options ...FieldOption) Builder
Int64 adds a 64-bit integer-based parameter to the expression Builder
func (Builder) ObjectID ¶
func (b Builder) ObjectID(name string, options ...FieldOption) Builder
ObjectID adds a mongodb ObjectID-based parameter to the expression Builder
func (Builder) Polygon ¶ added in v0.10.7
func (b Builder) Polygon(name string, options ...FieldOption) Builder
Polygon adds a GeoJSON polygon-based parameter to the expression Builder
type Field ¶ added in v0.7.7
Field describes a single queryable parameter: the expression field name, its data type, the default comparison operator, and any input filters.
type FieldOption ¶ added in v0.7.7
type FieldOption func(*Field)
FieldOption is a function that configures a Field during construction.
func WithAlias ¶ added in v0.7.7
func WithAlias(name string) FieldOption
WithAlias defines the field name to use when creating an expression, which may be different from the field name to read from the URL.
func WithDefaultOpBeginsWith ¶ added in v0.8.3
func WithDefaultOpBeginsWith() FieldOption
WithDefaultOpBeginsWith defines "BEGINS" as the default operator to use when creating an expression.
func WithDefaultOpContains ¶ added in v0.7.7
func WithDefaultOpContains() FieldOption
WithDefaultOpContains defines "CONTAINS" as the default operator to use when creating an expression.
func WithDefaultOpEqual ¶ added in v0.7.7
func WithDefaultOpEqual() FieldOption
WithDefaultOpEqual defines "EQUAL" as the default operator to use when creating an expression.
func WithDefaultOperator ¶ added in v0.7.7
func WithDefaultOperator(operator string) FieldOption
WithDefaultOperator defines the default operator to use when creating an expression
func WithFilter ¶ added in v0.9.0
func WithFilter(filter Filter) FieldOption
WithFilter adds a filter that transforms each input value before it is converted to the field's data type and compared.