where

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 0 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyOf added in v0.11.0

func AnyOf[T any](values []T) []any

AnyOf converts a typed slice into a []any so it can be spread into In or NotIn without per-call boilerplate. The variadic forms above require the spread either way; this helper closes the typed-slice footgun (`Field("id").In(stringIDs)` would silently match the literal slice value).

Type inference picks T from the argument; no explicit type parameter needed at the call site.

where.Field("id").In(where.AnyOf(stringIDs)...)
where.Field("status").NotIn(where.AnyOf(allStatuses)...)

Go does not allow generic methods on non-generic receivers, so a chained `.InSlice(stringIDs)` form is not possible — this top-level helper is the closest typed-spread the language permits.

Types

type Condition

type Condition interface {
	// FieldName returns the target field name, or "" for logical conditions.
	FieldName() string
	// contains filtered or unexported methods
}

Condition represents a query filter condition.

func And

func And(conditions ...Condition) Condition

And combines conditions with logical AND.

func Not

func Not(c Condition) Condition

Not negates a condition.

func Or

func Or(conditions ...Condition) Condition

Or combines conditions with logical OR.

type FieldBuilder

type FieldBuilder struct {
	// contains filtered or unexported fields
}

FieldBuilder provides a fluent API for building field conditions.

func Field

func Field(name string) FieldBuilder

Field starts building a condition on the named field. Supports dot notation for nested fields (e.g. "address.city").

func (FieldBuilder) Contains

func (fb FieldBuilder) Contains(value any) Condition

func (FieldBuilder) ContainsAll

func (fb FieldBuilder) ContainsAll(values ...any) Condition

func (FieldBuilder) ContainsAny

func (fb FieldBuilder) ContainsAny(values ...any) Condition

func (FieldBuilder) EndsWith added in v0.3.0

func (fb FieldBuilder) EndsWith(suffix string) Condition

EndsWith matches string fields that end with the given suffix.

func (FieldBuilder) Eq

func (fb FieldBuilder) Eq(value any) Condition

func (FieldBuilder) Gt

func (fb FieldBuilder) Gt(value any) Condition

func (FieldBuilder) Gte

func (fb FieldBuilder) Gte(value any) Condition

func (FieldBuilder) HasKey

func (fb FieldBuilder) HasKey(key string) Condition

HasKey checks whether a map field contains the given key.

func (FieldBuilder) In

func (fb FieldBuilder) In(values ...any) Condition

func (FieldBuilder) IsNil

func (fb FieldBuilder) IsNil() Condition

func (FieldBuilder) IsNotNil

func (fb FieldBuilder) IsNotNil() Condition

func (FieldBuilder) Lt

func (fb FieldBuilder) Lt(value any) Condition

func (FieldBuilder) Lte

func (fb FieldBuilder) Lte(value any) Condition

func (FieldBuilder) Ne

func (fb FieldBuilder) Ne(value any) Condition

func (FieldBuilder) NotIn

func (fb FieldBuilder) NotIn(values ...any) Condition

func (FieldBuilder) RegExp

func (fb FieldBuilder) RegExp(re any) Condition

RegExp matches the field value against a compiled regular expression.

func (FieldBuilder) StartsWith added in v0.3.0

func (fb FieldBuilder) StartsWith(prefix string) Condition

StartsWith matches string fields that start with the given prefix.

func (FieldBuilder) StringContains added in v0.3.0

func (fb FieldBuilder) StringContains(substr string) Condition

StringContains matches string fields that contain the given substring.

type FieldRef

type FieldRef string

FieldRef references another field for field-vs-field comparisons. Example: where.Field("end").Gt(where.FieldRef("start"))

type LogicType

type LogicType int

LogicType represents a logical combinator.

const (
	LogicAnd LogicType = iota
	LogicOr
)

type Operator

type Operator int

Operator represents a comparison operator.

const (
	OpEq Operator = iota
	OpNe
	OpGt
	OpGte
	OpLt
	OpLte
	OpIn
	OpNotIn
	OpIsNil
	OpIsNotNil
	OpContains
	OpContainsAny
	OpContainsAll
	OpRegExp
	OpHasKey
	OpStartsWith
	OpEndsWith
	OpStringContains
)

Jump to

Keyboard shortcuts

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