Documentation
¶
Index ¶
- Constants
- Variables
- func Cmp(f1 common.Serializable, op Operator, f2 common.Serializable) *cmp
- func CmpVal(f1 common.Serializable, op Operator, val common.Param) *cmpVal
- func Constant(s string) *constant
- func Eq(f common.FieldName, val common.Param) *cmpVal
- type Condition
- func AfterNext(field common.Serializable, duration time.Duration) Condition
- func And(cs ...Condition) Condition
- func BeforeNext(field common.Serializable, duration time.Duration) Condition
- func BetweenBytes(f common.FieldName, start, end []byte) Condition
- func BetweenInts(f common.FieldName, start, end int) Condition
- func BetweenStrings(f common.FieldName, start, end string) Condition
- func BetweenTimestamps(f common.FieldName, start, end time.Time) Condition
- func Exists(sq subquery) Condition
- func FieldBetweenInts(f common.Serializable, start, end int) Condition
- func FieldBetweenStrings(f common.Serializable, start, end string) Condition
- func FieldBetweenTimestamps(f common.Serializable, start, end time.Time) Condition
- func FieldIn[V common.Param](field common.Serializable, vals ...V) Condition
- func Gt[P comparable](f common.FieldName, val P) Condition
- func Gte[P comparable](f common.FieldName, val P) Condition
- func In[V common.Param](field common.FieldName, vals ...V) Condition
- func InFuture(field common.Serializable) Condition
- func InPast(field common.Serializable) Condition
- func InTuple(fields []common.Serializable, vals []Tuple) Condition
- func IsNil(f common.Serializable) Condition
- func Lt[P comparable](f common.FieldName, val P) Condition
- func Lte[P comparable](f common.FieldName, val P) Condition
- func Neq(f common.FieldName, val common.Param) Condition
- func NewerThan(field common.Serializable, duration time.Duration) Condition
- func Not(c Condition) Condition
- func NotExists(sq subquery) Condition
- func OlderThan(field common.Serializable, duration time.Duration) Condition
- func Or(cs ...Condition) Condition
- type Operator
- type Tuple
Constants ¶
const ( NoStringLimit = "" NoIntLimit = -1 )
Variables ¶
var ( AlwaysTrue = Constant("1 = 1") AlwaysFalse = Constant("1 = 0") )
Functions ¶
func Cmp ¶
func Cmp(f1 common.Serializable, op Operator, f2 common.Serializable) *cmp
Types ¶
type Condition ¶
func BeforeNext ¶
func BeforeNext(field common.Serializable, duration time.Duration) Condition
func Exists ¶ added in v0.14.2
func Exists(sq subquery) Condition
Exists creates an EXISTS (SELECT ...) condition wrapping the given subquery.
func FieldBetweenInts ¶
func FieldBetweenInts(f common.Serializable, start, end int) Condition
func FieldBetweenStrings ¶
func FieldBetweenStrings(f common.Serializable, start, end string) Condition
func FieldBetweenTimestamps ¶
func FieldBetweenTimestamps(f common.Serializable, start, end time.Time) Condition
func FieldIn ¶
func FieldIn[V common.Param](field common.Serializable, vals ...V) Condition
FieldIn returns the condition `field IN (vals...)`. An empty vals list means "no restriction" and yields AlwaysTrue, so the condition can be composed with And/Or without emitting invalid SQL.
func InFuture ¶
func InFuture(field common.Serializable) Condition
func InPast ¶
func InPast(field common.Serializable) Condition
func InTuple ¶
func InTuple(fields []common.Serializable, vals []Tuple) Condition
InTuple returns the condition `(fields...) IN (vals...)`, i.e. a membership test over a tuple of columns.
As with In/FieldIn, an empty fields or vals list means "no restriction" and yields AlwaysTrue. Returning a sentinel matters because And/Or only filter out conditions that are the AlwaysTrue/AlwaysFalse sentinel: a condition that rendered to the empty string would leave a dangling operator behind, e.g. `( AND status = $1)`.
Every tuple in vals must have exactly one value per field.
func IsNil ¶
func IsNil(f common.Serializable) Condition
func Not ¶ added in v0.24.0
Not negates the passed condition, e.g. Not(In("f", 1, 2)) renders as NOT ((f) IN (($0), ($1))). The inner condition is always parenthesised, so negating a composite (And/Or/In) keeps the intended precedence.
Note that SQL's three-valued logic applies: NOT (NULL = x) is NULL, not true, so a negated comparison never matches a row whose field is NULL. Add an explicit IsNil branch when NULL rows must also be matched.
func NotExists ¶ added in v0.24.0
func NotExists(sq subquery) Condition
NotExists creates a NOT EXISTS (SELECT ...) condition wrapping the given subquery. NOT EXISTS renders identically on every dialect, so - per the "Adding a condition" checklist in docs/development/sql-query-dsl.md - this implements WriteString directly rather than adding a CondInterpreter method.