expr

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 10 Imported by: 13

Documentation

Index

Constants

View Source
const NoSep = "\x00"

NoSep can be assigned to Join.Sep to join expressions with no separator at all. The zero value of Sep (empty string) still defaults to a single space for backward compatibility.

Variables

This section is empty.

Functions

func All added in v0.43.0

func All[T bob.Expression, B builder[T]](exp bob.Expression) T

ALL expression

func Any added in v0.43.0

func Any[T bob.Expression, B builder[T]](exp bob.Expression) T

ANY expression

func Arg added in v0.3.1

func Arg(vals ...any) bob.Expression

func ArgGroup added in v0.15.0

func ArgGroup(vals ...any) bob.Expression

Like Arg, but wraps in parentheses

func Cast added in v0.28.0

func Cast(e bob.Expression, typname string) bob.Expression

func Exists added in v0.43.0

func Exists[T bob.Expression, B builder[T]](exp bob.Expression) T

Exists expression

func Minus added in v0.43.0

func Minus[T bob.Expression, B builder[T]](exp bob.Expression) T

prefix the expression with a - (minus)

func Not

func Not[T bob.Expression, B builder[T]](exp bob.Expression) T

prefix the expression with a NOT

func OP

func OP(operator string, left, right any) bob.Expression

Generic operator between a left and right val

func Quote added in v0.2.0

func Quote(aa ...string) bob.Expression

func RawQuery

func RawQuery(d bob.Dialect, q string, args ...any) bob.BaseQuery[Clause]

func ToArgGroup added in v0.32.0

func ToArgGroup[T any](vals ...T) bob.Expression

func ToArgs added in v0.32.0

func ToArgs[T any](vals ...T) bob.Expression

func X

func X[T bob.Expression, B builder[T]](exp bob.Expression, others ...bob.Expression) T

Build an expression

Types

type Builder

type Builder[T bob.Expression, B builder[T]] struct{}

To be embedded in query mods T is the chain type, this allows dialects to have custom chain methods F is function type, so that the dialect can change where it accepted. E.g. it can be modified to work as a mod B has a New() method that is used to create a new instance of T

func (Builder[T, B]) All added in v0.43.0

func (e Builder[T, B]) All(exp bob.Expression) T

ALL expression

func (Builder[T, B]) And

func (e Builder[T, B]) And(args ...bob.Expression) T

And

func (Builder[T, B]) Any added in v0.43.0

func (e Builder[T, B]) Any(exp bob.Expression) T

ANY expression

func (Builder[T, B]) Arg

func (e Builder[T, B]) Arg(vals ...any) T

Comma separated list of arguments

func (Builder[T, B]) ArgGroup added in v0.15.0

func (e Builder[T, B]) ArgGroup(vals ...any) T

Comma separated list of arguments surrounded by parentheses

func (Builder[T, B]) Cast added in v0.28.0

func (e Builder[T, B]) Cast(exp bob.Expression, typname string) T

quoted and joined... something like "users"."id"

func (Builder[T, B]) Exists added in v0.43.0

func (e Builder[T, B]) Exists(exp bob.Expression) T

EXISTS expression

func (Builder[T, B]) Group

func (e Builder[T, B]) Group(exps ...bob.Expression) T

Add parentheses around an expressions and separate them by commas

func (Builder[T, B]) Minus added in v0.43.0

func (e Builder[T, B]) Minus(exp bob.Expression) T

prefix the expression with a - (minus)

func (Builder[T, B]) Not

func (e Builder[T, B]) Not(exp bob.Expression) T

prefix the expression with a NOT

func (Builder[T, B]) Or

func (e Builder[T, B]) Or(args ...bob.Expression) T

Or

func (Builder[T, B]) Placeholder

func (e Builder[T, B]) Placeholder(n uint) T

func (Builder[T, B]) Quote

func (e Builder[T, B]) Quote(aa ...string) T

quoted and joined... something like "users"."id"

func (Builder[T, B]) Raw

func (e Builder[T, B]) Raw(query string, args ...any) T

func (Builder[T, B]) S

func (e Builder[T, B]) S(s string) T

single quoted raw string

type CaseChain added in v0.29.0

type CaseChain[T bob.Expression, B builder[T]] func() caseExpr

func NewCase added in v0.29.0

func NewCase[T bob.Expression, B builder[T]]() CaseChain[T, B]

func (CaseChain[T, B]) Else added in v0.29.0

func (cc CaseChain[T, B]) Else(then bob.Expression) T

func (CaseChain[T, B]) End added in v0.29.0

func (cc CaseChain[T, B]) End() T

func (CaseChain[T, B]) When added in v0.29.0

func (cc CaseChain[T, B]) When(condition, then bob.Expression) CaseChain[T, B]

func (CaseChain[T, B]) WriteSQL added in v0.29.0

func (cc CaseChain[T, B]) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error)

type Chain

type Chain[T bob.Expression, B builder[T]] struct {
	Base bob.Expression
}

func (Chain[T, B]) And

func (x Chain[T, B]) And(targets ...bob.Expression) T

AND

func (Chain[T, B]) As

func (x Chain[T, B]) As(alias string) bob.Expression

As does not return a new chain. Should be used at the end of an expression useful for columns

func (Chain[T, B]) Between

func (x Chain[T, B]) Between(a, b bob.Expression) T

BETWEEN a AND b

func (Chain[T, B]) Concat

func (x Chain[T, B]) Concat(targets ...bob.Expression) T

Concatenate: ||

func (Chain[T, B]) EQ

func (x Chain[T, B]) EQ(target bob.Expression) T

Equal

func (Chain[T, B]) GT

func (x Chain[T, B]) GT(target bob.Expression) T

Greater than

func (Chain[T, B]) GTE

func (x Chain[T, B]) GTE(target bob.Expression) T

Greater than or equal to

func (Chain[T, B]) In

func (x Chain[T, B]) In(vals ...bob.Expression) T

IN

func (Chain[T, B]) IsDistinctFrom added in v0.2.0

func (x Chain[T, B]) IsDistinctFrom(exp bob.Expression) T

IS DISTINCT FROM

func (Chain[T, B]) IsNotDistinctFrom added in v0.2.0

func (x Chain[T, B]) IsNotDistinctFrom(exp bob.Expression) T

IS NOT DISTINCT FROM

func (Chain[T, B]) IsNotNull

func (x Chain[T, B]) IsNotNull() T

IS NOT NUll

func (Chain[T, B]) IsNull

func (x Chain[T, B]) IsNull() T

IS NUll

func (Chain[T, B]) LT

func (x Chain[T, B]) LT(target bob.Expression) T

Less than

func (Chain[T, B]) LTE

func (x Chain[T, B]) LTE(target bob.Expression) T

Less than or equal to

func (Chain[T, B]) Like added in v0.19.0

func (x Chain[T, B]) Like(target bob.Expression) T

Like operator

func (Chain[T, B]) Minus

func (x Chain[T, B]) Minus(target bob.Expression) T

Subtract

func (Chain[T, B]) NE

func (x Chain[T, B]) NE(target bob.Expression) T

Not Equal

func (Chain[T, B]) NotBetween

func (x Chain[T, B]) NotBetween(a, b bob.Expression) T

NOT BETWEEN a AND b

func (Chain[T, B]) NotIn

func (x Chain[T, B]) NotIn(vals ...bob.Expression) T

NOT IN

func (Chain[T, B]) OP added in v0.23.0

func (x Chain[T, B]) OP(op string, target bob.Expression) T

Generic Operator

func (Chain[T, B]) Or

func (x Chain[T, B]) Or(targets ...bob.Expression) T

OR

func (Chain[T, B]) Plus added in v0.42.0

func (x Chain[T, B]) Plus(target bob.Expression) T

Addition

func (Chain[T, B]) WriteSQL

func (x Chain[T, B]) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error)

WriteSQL satisfies the bob.Expression interface

type Clause added in v0.18.0

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

A Raw Clause with arguments

func (Clause) ShouldOmitParens added in v0.45.0

func (Clause) ShouldOmitParens() bool

ShouldOmitParens reports that Clause is expected to be printed as it is.

func (Clause) WriteSQL added in v0.18.0

func (r Clause) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error)

type ColumnsExpr added in v0.40.0

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

ColumnsExpr is a set of columns that can be used in a query It is used to properly quote and format the columns in the query such as "users"."id" AS "id", "users"."name" AS "name"

func ColsForStruct added in v0.40.0

func ColsForStruct[T any](name string) ColumnsExpr

func NewColumnsExpr added in v0.40.0

func NewColumnsExpr(names ...string) ColumnsExpr

NewColumnsExpr returns a ColumnsExpr object with the given column names

func (ColumnsExpr) AggFunc added in v0.44.0

func (c ColumnsExpr) AggFunc() [2]string

AggFunc returns the aggregation function of the columns

func (ColumnsExpr) AliasDisabled added in v0.44.0

func (c ColumnsExpr) AliasDisabled() bool

AliasDisabled returns whether aliasing is disabled for the columns

func (ColumnsExpr) AliasPrefix added in v0.44.0

func (c ColumnsExpr) AliasPrefix() string

AliasPrefix returns the alias prefix of the columns

func (ColumnsExpr) DisableAlias added in v0.40.0

func (c ColumnsExpr) DisableAlias() ColumnsExpr

DisableAlias disables adding 'AS "prefix_column_name"' when writing SQL.

func (ColumnsExpr) EnableAlias added in v0.40.0

func (c ColumnsExpr) EnableAlias() ColumnsExpr

EnableAlias enables adding 'AS "prefix_column_name"' when writing SQL.

func (ColumnsExpr) Except added in v0.40.0

func (c ColumnsExpr) Except(cols ...string) ColumnsExpr

Except drops the given column names from the column set

func (ColumnsExpr) Names added in v0.40.0

func (c ColumnsExpr) Names() []string

Names returns the names of the columns

func (ColumnsExpr) Only added in v0.40.0

func (c ColumnsExpr) Only(cols ...string) ColumnsExpr

Only drops other column names from the column set

func (ColumnsExpr) Parent added in v0.44.0

func (c ColumnsExpr) Parent() []string

Parent returns the parent columns

func (ColumnsExpr) WithAggFunc added in v0.40.0

func (c ColumnsExpr) WithAggFunc(a, b string) ColumnsExpr

func (ColumnsExpr) WithParent added in v0.40.0

func (c ColumnsExpr) WithParent(p ...string) ColumnsExpr

WithParent sets the parent of the columns.

func (ColumnsExpr) WithPrefix added in v0.40.0

func (c ColumnsExpr) WithPrefix(prefix string) ColumnsExpr

WithPrefix sets the prefix of the aliases of the column set.

func (ColumnsExpr) WriteSQL added in v0.40.0

func (c ColumnsExpr) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error)

type Join

type Join struct {
	Exprs []bob.Expression
	Sep   string
}

If Sep is empty, a space is used. Set Sep to NoSep to use no separator.

func (Join) WriteSQL

func (s Join) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error)

type Raw

type Raw string

func (Raw) ShouldOmitParens added in v0.45.0

func (Raw) ShouldOmitParens() bool

ShouldOmitParens reports that Raw is expected to be printed as it is.

func (Raw) WriteSQL

func (r Raw) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error)

Jump to

Keyboard shortcuts

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