Documentation
¶
Index ¶
- type AndExpr
- func (e *AndExpr) And(ands ...LogicalExpr) *AndExpr
- func (e AndExpr) Base() interface{}
- func (e AndExpr) Empty() bool
- func (e AndExpr) Expressions() []LogicalExpr
- func (e AndExpr) Fn(in interface{}) error
- func (e AndExpr) Operator() LogicalOperator
- func (e AndExpr) Prev() immutable.Immutable
- func (e AndExpr) String() string
- type Comparison
- func After(value time.Time) *Comparison
- func AnyOf(value interface{}) *Comparison
- func Before(value time.Time) *Comparison
- func Between(lower, upper interface{}) *Comparison
- func Eq(value interface{}) *Comparison
- func Gt(value interface{}) *Comparison
- func Gte(value interface{}) *Comparison
- func In(value ...interface{}) *Comparison
- func Is(value interface{}) *Comparison
- func IsNot(value interface{}) *Comparison
- func IsNotNull() *Comparison
- func IsNull() *Comparison
- func Like(value string) *Comparison
- func Lt(value interface{}) *Comparison
- func Lte(value interface{}) *Comparison
- func NotAnyOf(value interface{}) *Comparison
- func NotBetween(lower, upper interface{}) *Comparison
- func NotEq(value interface{}) *Comparison
- func NotIn(value ...interface{}) *Comparison
- func NotLike(value string) *Comparison
- func NotRegexp(value string) *Comparison
- func OnOrAfter(value time.Time) *Comparison
- func OnOrBefore(value time.Time) *Comparison
- func Op(op string, value interface{}) *Comparison
- func Regexp(value string) *Comparison
- type ComparisonOperator
- type Cond
- type Constraint
- type Constraints
- type FuncExpr
- type LogicalExpr
- type LogicalOperator
- type OrExpr
- func (e OrExpr) Base() interface{}
- func (e OrExpr) Empty() bool
- func (e OrExpr) Expressions() []LogicalExpr
- func (e OrExpr) Fn(in interface{}) error
- func (e OrExpr) Operator() LogicalOperator
- func (e *OrExpr) Or(ors ...LogicalExpr) *OrExpr
- func (e OrExpr) Prev() immutable.Immutable
- func (e OrExpr) String() string
- type RawExpr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AndExpr ¶
type AndExpr struct {
// contains filtered or unexported fields
}
AndExpr is an expression that joins child expressions by logical conjunctions.
func And ¶
func And(exprs ...LogicalExpr) *AndExpr
And joins given expressions by logical conjunctions (LogicalAnd). Expressions can be represented by mixes of `expr.Cond{}`, `expr.Or()` and `expr.And()`.
Examples:
=> name = 'Peter' AND last_name = 'Parker'
expr.And(
expr.Cond{"name": "Peter"},
expr.Cond{"last_name": "Parker "},
)
=> (name = 'Peter' OR name = 'Mickey') AND last_name = 'Mouse'
expr.And(
expr.Or(
expr.Cond{"name": "Peter"},
expr.Cond{"name": "Mickey"},
),
expr.Cond{"last_name": "Mouse"},
)
func (*AndExpr) And ¶
func (e *AndExpr) And(ands ...LogicalExpr) *AndExpr
And adds more AND conditions to the expression.
func (AndExpr) Expressions ¶
func (e AndExpr) Expressions() []LogicalExpr
func (AndExpr) Operator ¶
func (e AndExpr) Operator() LogicalOperator
type Comparison ¶
type Comparison struct {
// contains filtered or unexported fields
}
Comparison represents the relationship between values.
func After ¶
func After(value time.Time) *Comparison
After is a comparison that means: is after the time.
func AnyOf ¶
func AnyOf(value interface{}) *Comparison
AnyOf is a comparison that means: is any of the values of the slice.
func Before ¶
func Before(value time.Time) *Comparison
Before is a comparison that means: is before the time.
func Between ¶
func Between(lower, upper interface{}) *Comparison
Between is a comparison that means: is between lower and upper bound.
func Eq ¶
func Eq(value interface{}) *Comparison
Eq is a comparison that means: is equal to the value.
func Gt ¶
func Gt(value interface{}) *Comparison
Gt is a comparison that means: is greater than the value.
func Gte ¶
func Gte(value interface{}) *Comparison
Gte is a comparison that means: is greater than or equal to the value.
func In ¶
func In(value ...interface{}) *Comparison
In is a comparison that means: is any of the values.
func Is ¶
func Is(value interface{}) *Comparison
Is is a comparison that means: is equivalent to nil, true or false.
func IsNot ¶
func IsNot(value interface{}) *Comparison
IsNot is a comparison that means: is not equivalent to nil, true nor false.
func IsNotNull ¶
func IsNotNull() *Comparison
IsNotNull is a comparison that means: is not equivalent to nil.
func Like ¶
func Like(value string) *Comparison
Like is a comparison that checks whether the reference matches the wildcard of the value.
func Lt ¶
func Lt(value interface{}) *Comparison
Lt is a comparison that means: is less than the value.
func Lte ¶
func Lte(value interface{}) *Comparison
Lte is a comparison that means: is less than or equal to the value.
func NotAnyOf ¶
func NotAnyOf(value interface{}) *Comparison
NotAnyOf is a comparison that means: is none of the values of the slice.
func NotBetween ¶
func NotBetween(lower, upper interface{}) *Comparison
NotBetween is a comparison that means: is not between lower and upper bound.
func NotEq ¶
func NotEq(value interface{}) *Comparison
NotEq is a comparison that means: is not equal to the value.
func NotIn ¶
func NotIn(value ...interface{}) *Comparison
NotIn is a comparison that means: is none of the values.
func NotLike ¶
func NotLike(value string) *Comparison
NotLike is a comparison that checks whether the reference does not match the wildcard of the value.
func NotRegexp ¶
func NotRegexp(value string) *Comparison
NotRegexp is a comparison that checks whether the reference does not match the regular expression.
func OnOrAfter ¶
func OnOrAfter(value time.Time) *Comparison
OnOrAfter is a comparison that means: is on or after the time.
func OnOrBefore ¶
func OnOrBefore(value time.Time) *Comparison
OnOrBefore is a comparison that means: is on or before the time.
func Op ¶
func Op(op string, value interface{}) *Comparison
Op returns a comparison with the custom operator.
func Regexp ¶
func Regexp(value string) *Comparison
Regexp is a comparison that checks whether the reference matches the regular expression.
func (*Comparison) CustomOperator ¶
func (c *Comparison) CustomOperator() string
CustomOperator returns the custom operator of the comparison.
func (*Comparison) Operator ¶
func (c *Comparison) Operator() ComparisonOperator
Operator returns the ComparisonOperator.
func (*Comparison) Value ¶
func (c *Comparison) Value() interface{}
Value returns the value of the comparison.
type ComparisonOperator ¶
type ComparisonOperator uint8
ComparisonOperator is a comparison operator.
const ( ComparisonNone ComparisonOperator = iota ComparisonCustom ComparisonEqual ComparisonNotEqual ComparisonLessThan ComparisonGreaterThan ComparisonLessThanOrEqualTo ComparisonGreaterThanOrEqualTo ComparisonBetween ComparisonNotBetween ComparisonIn ComparisonNotIn ComparisonIs ComparisonIsNot ComparisonLike ComparisonNotLike ComparisonRegexp ComparisonNotRegexp )
type Cond ¶
type Cond map[interface{}]interface{}
Cond is a map that defines conditions for a query.
Each entry of the map represents a constraint (a column-value relation bound by a ComparisonOperator). The comparison can be specified after the column name, if no ComparisonOperator is provided the equality operator (LogicalAnd) is used as the default.
Examples:
=> age = 18
expr.Cond{"age": 18}
=> age >= 18
expr.Cond{"age >=": 18}
=> id IN (1, 2, 3)
expr.Cond{"id IN": []{1, 2, 3}}
=> age > 32 AND age < 35
expr.Cond{"age >": 32, "age <": 35}
func (Cond) Constraints ¶
func (c Cond) Constraints() []Constraint
Constraints returns each one of the Cond entries as constraints.
func (Cond) Expressions ¶
func (c Cond) Expressions() []LogicalExpr
func (Cond) Operator ¶
func (c Cond) Operator() LogicalOperator
type Constraint ¶
type Constraint interface {
// Key is the leftmost part of the constraint and usually contains a column
// name.
Key() interface{}
// Value if the rightmost part of the constraint and usually contains a column
// value.
Value() interface{}
}
Constraint represents a single condition like "a = 1", where "a" is the key and "1" is the value.
func NewConstraint ¶
func NewConstraint(key interface{}, value interface{}) Constraint
NewConstraint constructs a new constraint with the given key and value.
type Constraints ¶
type Constraints interface {
// Constraints returns the list of constraints.
Constraints() []Constraint
}
Constraints represents a list of constraints, like "a = 1, b = 2, c = 3".
type FuncExpr ¶
type FuncExpr struct {
*RawExpr
}
FuncExpr is similar to RawExpr but is designed for database functions.
type LogicalExpr ¶
type LogicalExpr interface {
// Expressions returns all child expressions in the logical expression.
Expressions() []LogicalExpr
// Operator returns the Operator that joins all the child expressions in the
// logical expression.
Operator() LogicalOperator
// Empty returns true if the logical expression has no child expressions.
Empty() bool
fmt.Stringer
}
LogicalExpr represents an expression to be used in logical statements. It consists of a group of expressions joined by operators like LogicalAnd or LogicalOr.
func Logical ¶
func Logical(op LogicalOperator, exprs ...LogicalExpr) LogicalExpr
Logical constructs a LogicalExpr with given operator and expressions.
type LogicalOperator ¶
type LogicalOperator uint
LogicalOperator is a logical operation on a compound statement.
const ( LogicalNone LogicalOperator = iota LogicalAnd LogicalOr )
func (LogicalOperator) String ¶
func (op LogicalOperator) String() string
type OrExpr ¶
type OrExpr struct {
// contains filtered or unexported fields
}
OrExpr is an expression that joins child expressions by logical disjunction.
func Or ¶
func Or(exprs ...LogicalExpr) *OrExpr
Or joins given expressions by logical disjunction (LogicalOr). Expressions can be represented by mixes of `expr.Cond{}`, `expr.Or()`, `expr.And()` and `expr.Raw()`.
Example:
=> year = 2012 OR year = 1987
expr.Or(
expr.Cond{"year": 2012},
expr.Cond{"year": 1987},
)
func (OrExpr) Expressions ¶
func (e OrExpr) Expressions() []LogicalExpr
func (OrExpr) Operator ¶
func (e OrExpr) Operator() LogicalOperator
func (*OrExpr) Or ¶
func (e *OrExpr) Or(ors ...LogicalExpr) *OrExpr
Or adds more OR conditions to the expression.
type RawExpr ¶
type RawExpr struct {
// contains filtered or unexported fields
}
RawExpr is a raw expression that can bypass SQL filters.
func Raw ¶
Raw keeps the given value and arguments unfiltered and passes them directly to the query .
CAUTION: It is possible to cause SQL injection if user inputs are not properly sanitized before giving to this function.
Example:
=> SOUNDEX('Hello')
expr.Raw("SOUNDEX('Hello')")
func (*RawExpr) Arguments ¶
func (e *RawExpr) Arguments() []interface{}
Arguments returns arguments of the raw expression. It returns nil if there is no argument.
func (*RawExpr) Expressions ¶
func (e *RawExpr) Expressions() []LogicalExpr
func (RawExpr) Operator ¶
func (e RawExpr) Operator() LogicalOperator