Documentation
¶
Index ¶
- func WithIn(values ...string) optionValidateFunc
- func WithMax(max string) optionValidateFunc
- func WithMin(min string) optionValidateFunc
- func WithNotAllowed() optionValidateFunc
- func WithNotEmpty() optionValidateFunc
- func WithNotIn(values ...string) optionValidateFunc
- func WithNotOperator(operators ...OperatorCmpType) optionValidateFunc
- func WithOperator(operators ...OperatorCmpType) optionValidateFunc
- func WithRequired() optionValidateFunc
- type Expression
- type ExpressionCmp
- type ExpressionLogic
- type ExpressionSort
- type OperatorCmpType
- type OperatorLogicType
- type OptionQuery
- type OptionValidate
- type OptionValidateSet
- func WithField(opts ...optionValidateFunc) OptionValidateSet
- func WithLimit(opts ...optionValidateFunc) OptionValidateSet
- func WithOffset(opts ...optionValidateFunc) OptionValidateSet
- func WithSort(opts ...optionValidateFunc) OptionValidateSet
- func WithValue(key string, opts ...optionValidateFunc) OptionValidateSet
- func WithValues(opts ...optionValidateFunc) OptionValidateSet
- type Query
- func (q *Query) CloneLimit() *uint64
- func (q *Query) CloneOffset() *uint64
- func (q *Query) GetLimit() uint64
- func (q *Query) GetOffset() uint64
- func (q *Query) GetValue(v string) string
- func (q *Query) GetValues(v string) []string
- func (q *Query) Has(v string) bool
- func (q *Query) HasAny(vList ...string) bool
- func (q *Query) Validate(v *Validator) error
- func (q *Query) Walk(fn func(Token) error) error
- type Token
- type Validator
- type WalkType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithIn ¶
func WithIn(values ...string) optionValidateFunc
WithIn checks if the value is in the list of values.
- Usable for 'WithValue', 'WithSort', 'WithValues', 'WithFields'
func WithMax ¶
func WithMax(max string) optionValidateFunc
WithMax to validate the maximum of a value.
- Usable for 'WithValue', 'WithLimit', 'WithOffset'
func WithMin ¶
func WithMin(min string) optionValidateFunc
WithMin to validate the minimum of a value.
- Usable for 'WithValue', WithSort', 'WithLimit'
func WithNotAllowed ¶ added in v0.1.2
func WithNotAllowed() optionValidateFunc
WithNotAllowed to validate the value is not allowed.
- Usable for 'WithValue', 'WithOffset', 'WithLimit', 'WithSort', 'WithValues', 'WithFields'
func WithNotEmpty ¶
func WithNotEmpty() optionValidateFunc
WithNotEmpty to validate the value is not empty.
- Usable for 'WithValue'
func WithNotIn ¶
func WithNotIn(values ...string) optionValidateFunc
WithNotIn checks if the value is not in the list of values.
- Usable for 'WithValue', 'WithSort', 'WithValues', 'WithFields'
func WithNotOperator ¶ added in v0.1.4
func WithNotOperator(operators ...OperatorCmpType) optionValidateFunc
WithNotOperator to validate the operator is not allowed.
- Usable for 'WithValue'
func WithOperator ¶ added in v0.1.4
func WithOperator(operators ...OperatorCmpType) optionValidateFunc
WithOperator to validate the operator is allowed.
- Usable for 'WithValue'
func WithRequired ¶
func WithRequired() optionValidateFunc
WithRequired to validate the value is required.
- Usable for 'WithValue'
Types ¶
type Expression ¶
type Expression interface {
Expression() Expression
}
type ExpressionCmp ¶
type ExpressionCmp struct {
Operator OperatorCmpType
Field string
Value any
}
func (ExpressionCmp) Expression ¶
func (e ExpressionCmp) Expression() Expression
type ExpressionLogic ¶
type ExpressionLogic struct {
Operator OperatorLogicType
List []Expression
}
func (ExpressionLogic) Expression ¶
func (e ExpressionLogic) Expression() Expression
type ExpressionSort ¶ added in v0.1.10
type OperatorCmpType ¶
type OperatorCmpType string
const ( // OperatorEmpty is the empty operator. OperatorEmpty OperatorCmpType = "" // OperatorEq is the equality operator. OperatorEq OperatorCmpType = "eq" // OperatorNe is the not equal operator. OperatorNe OperatorCmpType = "ne" // OperatorGt is the greater than operator. OperatorGt OperatorCmpType = "gt" // OperatorLt is the less than operator. OperatorLt OperatorCmpType = "lt" // OperatorGte is the greater than or equal operator. OperatorGte OperatorCmpType = "gte" // OperatorLte is the less than or equal operator. OperatorLte OperatorCmpType = "lte" // OperatorLike is the like operator. OperatorLike OperatorCmpType = "like" // OperatorILike is the case insensitive like operator. OperatorILike OperatorCmpType = "ilike" // OperatorNLike is the not like operator. OperatorNLike OperatorCmpType = "nlike" // OperatorNILike is the case insensitive not like operator. OperatorNILike OperatorCmpType = "nilike" // OperatorIn is the in operator. OperatorIn OperatorCmpType = "in" // OperatorNIn is the not in operator. OperatorNIn OperatorCmpType = "nin" // OperatorIs is the is null operator. OperatorIs OperatorCmpType = "is" // OperatorIsNot is the is not null operator. OperatorIsNot OperatorCmpType = "not" )
type OperatorLogicType ¶
type OperatorLogicType string
const ( // OperatorAnd is the AND operator. OperatorAnd OperatorLogicType = "and" // OperatorOr is the OR operator. OperatorOr OperatorLogicType = "or" )
type OptionQuery ¶ added in v0.1.2
type OptionQuery func(*optionQuery)
func WithDefaultLimit ¶ added in v0.1.2
func WithDefaultLimit(limit uint64) OptionQuery
WithDefaultLimit sets the default limit value.
func WithDefaultOffset ¶ added in v0.1.2
func WithDefaultOffset(offset uint64) OptionQuery
WithDefaultOffset sets the default offset value.
func WithExpressionCmp ¶ added in v0.1.2
func WithExpressionCmp(key string, value ExpressionCmp) OptionQuery
WithExpressionCmp sets the expression comparison for a given key.
func WithSkipExpressionCmp ¶ added in v0.1.3
func WithSkipExpressionCmp(key ...string) OptionQuery
WithSkipExpressionCmp sets the keys to be skipped in the query.
type OptionValidate ¶
type OptionValidate func(string, ...optionValidateFunc)
type OptionValidateSet ¶
func WithField ¶
func WithField(opts ...optionValidateFunc) OptionValidateSet
func WithLimit ¶ added in v0.1.10
func WithLimit(opts ...optionValidateFunc) OptionValidateSet
func WithOffset ¶ added in v0.1.10
func WithOffset(opts ...optionValidateFunc) OptionValidateSet
func WithSort ¶ added in v0.1.10
func WithSort(opts ...optionValidateFunc) OptionValidateSet
func WithValue ¶
func WithValue(key string, opts ...optionValidateFunc) OptionValidateSet
func WithValues ¶ added in v0.1.2
func WithValues(opts ...optionValidateFunc) OptionValidateSet
type Query ¶
type Query struct {
Values map[string][]ExpressionCmp
Select []string
Where []Expression
Sort []ExpressionSort
Offset *uint64
Limit *uint64
}
func Parse ¶
func Parse(query string, opts ...OptionQuery) (*Query, error)
Parse parses a query string into a Query struct.
func ParseWithValidator ¶ added in v0.1.2
func ParseWithValidator(query string, validator *Validator, opts ...OptionQuery) (*Query, error)
func (*Query) CloneLimit ¶ added in v0.1.3
func (*Query) CloneOffset ¶ added in v0.1.3
type Token ¶
type Token struct {
Expression Expression
Type WalkType
}
type Validator ¶ added in v0.1.1
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator ¶
func NewValidator(opts ...OptionValidateSet) (*Validator, error)