Documentation
¶
Overview ¶
Package filter builds WHERE conditions from optional inputs. A nil BoolExpression means "no condition". It is dropped by All and Any, and WHERE(nil) on a SELECT writes no WHERE clause.
stmt := SELECT(Invoice.AllColumns).FROM(Invoice).WHERE(filter.All(
Invoice.TenantID.EQ(UUID(f.Tenant)),
filter.When(f.Status, func(s string) BoolExpression { return Invoice.Status.EQ(String(s)) }),
filter.When(f.From, func(t time.Time) BoolExpression { return Invoice.CreatedAt.GT_EQ(TimestampzT(t)) }),
))
UPDATE and DELETE keep their mandatory WHERE: when every condition is absent, All returns nil and the statement panics with "WHERE clause not set" instead of changing every row. Always include a non-optional key predicate in writes.
Upstream AND, OR and WHERE are unchanged (AND() with no argument still panics).
This package is Nanostack-only (not in go-jet). See db/UPSTREAM.md.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoolExpression ¶
type BoolExpression = jet.BoolExpression
BoolExpression is the condition type of every dialect.
func All ¶
func All(conds ...BoolExpression) BoolExpression
All ANDs the non-nil conditions. Zero conditions give nil. One condition is returned unchanged. Two or more give jet's AND of them.
func Any ¶
func Any(conds ...BoolExpression) BoolExpression
Any ORs the non-nil conditions. Zero conditions give nil, which means "no restriction" (not FALSE).
func If ¶
func If(ok bool, cond func() BoolExpression) BoolExpression
If returns cond() when ok is true, and nil otherwise. cond is called only when ok is true, so it may build expressions that would be invalid otherwise (an IN over an empty list).
func When ¶
func When[T any](o functional.Option[T], cond func(T) BoolExpression) BoolExpression
When returns cond(v) when o carries v, and nil when o is absent.