cond

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoStringLimit = ""
	NoIntLimit    = -1
)

Variables

View Source
var (
	AlwaysTrue  = Constant("1 = 1")
	AlwaysFalse = Constant("1 = 0")
)

Functions

func Cmp

func Cmp(f1 common.Serializable, op Operator, f2 common.Serializable) *cmp

func CmpVal

func CmpVal(f1 common.Serializable, op Operator, val common.Param) *cmpVal

func Constant

func Constant(s string) *constant

func Eq

func Eq(f common.FieldName, val common.Param) *cmpVal

Types

type Condition

type Condition = common.Condition

func AfterNext

func AfterNext(field common.Serializable, duration time.Duration) Condition

func And

func And(cs ...Condition) Condition

func BeforeNext

func BeforeNext(field common.Serializable, duration time.Duration) Condition

func BetweenBytes

func BetweenBytes(f common.FieldName, start, end []byte) Condition

func BetweenInts

func BetweenInts(f common.FieldName, start, end int) Condition

func BetweenStrings

func BetweenStrings(f common.FieldName, start, end string) Condition

func BetweenTimestamps

func BetweenTimestamps(f common.FieldName, start, end time.Time) 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 Gt

func Gt[P comparable](f common.FieldName, val P) Condition

func Gte

func Gte[P comparable](f common.FieldName, val P) Condition

func In

func In[V common.Param](field common.FieldName, vals ...V) Condition

In returns the condition `field IN (vals...)`. See FieldIn for the empty-list behaviour.

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 Lt

func Lt[P comparable](f common.FieldName, val P) Condition

func Lte

func Lte[P comparable](f common.FieldName, val P) Condition

func Neq

func NewerThan

func NewerThan(field common.Serializable, duration time.Duration) Condition

func Not added in v0.24.0

func Not(c Condition) Condition

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.

func OlderThan

func OlderThan(field common.Serializable, duration time.Duration) Condition

func Or

func Or(cs ...Condition) Condition

type Operator

type Operator = string

type Tuple

type Tuple = common.Tuple

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL