expr

package
v0.0.0-...-f7d8b6d Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package expr contains functions that produce sqlb structs that can be chained together to form SQL statements and ultimately passed to sqlb's [sqlb.Query] and [sqlb.QueryContext] functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And(
	leftAny interface{},
	rightAny interface{},
) *grammar.BooleanValueExpression

And accepts two things and returns a BooleanValueExpression ANDing the two things together. This boolean value expression can be passed to a Join or Where clause.

And panics if sqlb cannot compile the supplied arguments into a valid BooleanValueExpression. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of And() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `AndE` function which returns a checkable `error` object.

func AndE

func AndE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.BooleanValueExpression, error)

AndE accepts two things and returns a BooleanValueExpression ANDing the two things together. This boolean value expression can be passed to a Join or Where clause. If the two parameters cannot be compiled into a BooleanValueExpression, an error is returned.

func Between

func Between(
	targetAny interface{},
	startAny interface{},
	endAny interface{},
) *grammar.BetweenPredicate

Between accepts three things and returns a BetweenPredicate representing a SQL BETWEEN expression that can be passed to a Join or Where clause.

Between panics if sqlb cannot compile the supplied arguments into a valid BetweenPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of Between() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `BetweenE` function which returns a checkable `error` object.

func BetweenE

func BetweenE(
	targetAny interface{},
	startAny interface{},
	endAny interface{},
) (*grammar.BetweenPredicate, error)

BetweenE accepts three things and returns a BetweenPredicate representing a SQL BETWEEN expression that can be passed to a Join or Where clause. If the supplied arguments cannot be compiled into a valid BetweenPredicate, an error is returned.

func Equal

func Equal(
	leftAny interface{},
	rightAny interface{},
) *grammar.ComparisonPredicate

Equal accepts two things and returns a ComparisonPredicate representing an equality expression that can be passed to a Join or Where clause.

Equal panics if sqlb cannot compile the supplied arguments into a valid ComparisonPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of Equal() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `EqualE` function which returns a checkable `error` object.

func EqualE

func EqualE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.ComparisonPredicate, error)

EqualE accepts two things and returns a ComparisonPredicate representing an equality expression that can be passed to a Join or Where clause. If the two supplied parameters cannot be evaluated into a ComparisonPredicate, an error is returned.

func GreaterThan

func GreaterThan(
	leftAny interface{},
	rightAny interface{},
) *grammar.ComparisonPredicate

GreaterThan accepts two things and returns a ComparisonPredicate representing greater than expression that can be passed to a Join or Where clause.

GreaterThan panics if sqlb cannot compile the supplied arguments into a valid ComparisonPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of GreaterThan() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `GreaterThanE` function which returns a checkable `error` object.

func GreaterThanE

func GreaterThanE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.ComparisonPredicate, error)

GreaterThanE accepts two things and returns a ComparisonPredicate representing greater than expression that can be passed to a Join or Where clause. If the two supplied parameters cannot be evaluated into a ComparisonPredicate, an error is returned.

func GreaterThanOrEqual

func GreaterThanOrEqual(
	leftAny interface{},
	rightAny interface{},
) *grammar.ComparisonPredicate

GreaterThanOrEqual accepts two things and returns a ComparisonPredicate representing greater than or equal expression that can be passed to a Join or Where clause.

GreaterThanOrEqual panics if sqlb cannot compile the supplied arguments into a valid ComparisonPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of GreaterThanOrEqual() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `GreaterThanOrEqualE` function which returns a checkable `error` object.

func GreaterThanOrEqualE

func GreaterThanOrEqualE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.ComparisonPredicate, error)

GreaterThanOrEqualE accepts two things and returns a ComparisonPredicate representing greater than or equal expression that can be passed to a Join or Where clause. If the two supplied parameters cannot be evaluated into a ComparisonPredicate, an error is returned.

func In

func In(
	targetAny interface{},
	values ...interface{},
) *grammar.InPredicate

In accepts two things and returns an InPredicate representing an IN expression that can be passed to a Join or Where clause.

In panics if sqlb cannot compile the supplied arguments into a valid InPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of In() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `InE` function which returns a checkable `error` object.

func InE

func InE(
	targetAny interface{},
	values ...interface{},
) (*grammar.InPredicate, error)

In accepts two things and returns an InPredicate representing an IN expression that can be passed to a Join or Where clause. If the supplied arguments cannot be compiled into a valid InPredicate, an error is returned.

func IsNotNull

func IsNotNull(
	targetAny interface{},
) *grammar.NullPredicate

IsNotNull accepts a thing and returns a NullPredicate representing an IS NOT NULL expression that can be passed to a Join or Where clause.

IsNotNull panics if sqlb cannot compile the supplied arguments into a valid NullPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of IsNotNull() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `IsNotNullE` function which returns a checkable `error` object.

func IsNotNullE

func IsNotNullE(
	targetAny interface{},
) (*grammar.NullPredicate, error)

IsNotNullE accepts a thing and returns a NullPredicate representing an IS NOT NULL expression that can be passed to a Join or Where clause. If the supplied parameter cannot be converted into a RowValuePredicand, an error is returned.

func IsNull

func IsNull(
	targetAny interface{},
) *grammar.NullPredicate

IsNull accepts a thing and returns a NullPredicate representing an IS NULL expression that can be passed to a Join or Where clause.

IsNull panics if sqlb cannot compile the supplied arguments into a valid NullPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of IsNull() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `IsNullE` function which returns a checkable `error` object.

func IsNullE

func IsNullE(
	targetAny interface{},
) (*grammar.NullPredicate, error)

IsNullE accepts a thing and returns a NullPredicate representing an IS NULL expression that can be passed to a Join or Where clause. If the supplied parameter cannot be converted into a RowValuePredicand, an error is returned.

func LessThan

func LessThan(
	leftAny interface{},
	rightAny interface{},
) *grammar.ComparisonPredicate

LessThan accepts two things and returns a ComparisonPredicate representing less than expression that can be passed to a Join or Where clause.

LessThan panics if sqlb cannot compile the supplied arguments into a valid ComparisonPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of LessThan() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `LessThanE` function which returns a checkable `error` object.

func LessThanE

func LessThanE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.ComparisonPredicate, error)

LessThanE accepts two things and returns a ComparisonPredicate representing less than expression that can be passed to a Join or Where clause. If the two supplied parameters cannot be evaluated into a ComparisonPredicate, an error is returned.

func LessThanOrEqual

func LessThanOrEqual(
	leftAny interface{},
	rightAny interface{},
) *grammar.ComparisonPredicate

LessThanOrEqual accepts two things and returns a ComparisonPredicate representing less than or equal expression that can be passed to a Join or Where clause.

LessThanOrEqual panics if sqlb cannot compile the supplied arguments into a valid ComparisonPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of LessThanOrEqual() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `LessThanOrEqualE` function which returns a checkable `error` object.

func LessThanOrEqualE

func LessThanOrEqualE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.ComparisonPredicate, error)

LessThanOrEqualE accepts two things and returns a ComparisonPredicate representing less than or equal expression that can be passed to a Join or Where clause. If the two supplied parameters cannot be evaluated into a ComparisonPredicate, an error is returned.

func NotEqual

func NotEqual(
	leftAny interface{},
	rightAny interface{},
) *grammar.ComparisonPredicate

NotEqual accepts two things and returns a ComparisonPredicate representing an inequality expression that can be passed to a Join or Where clause.

NotEqual panics if sqlb cannot compile the supplied arguments into a valid ComparisonPredicate. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of NotEqual() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `NotEqualE` function which returns a checkable `error` object.

func NotEqualE

func NotEqualE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.ComparisonPredicate, error)

NotEqualE accepts two things and returns a ComparisonPredicate representing an inequality expression that can be passed to a Join or Where clause. If the two supplied parameters cannot be evaluated into a ComparisonPredicate, an error is returned.

func Or

func Or(
	leftAny interface{},
	rightAny interface{},
) *grammar.BooleanValueExpression

Or accepts two things and returns an Element representing an OR expression that can be passed to a Join or Where clause.

Or panics if sqlb cannot compile the supplied arguments into a valid BooleanValueExpression. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of Or() to be passed directly into other `core/expr` functions.

If you are constructing SQL expressions dynamically with user-supplied input, use the `OrE` function which returns a checkable `error` object.

func OrE

func OrE(
	leftAny interface{},
	rightAny interface{},
) (*grammar.BooleanValueExpression, error)

OrE accepts two things and returns a BooleanValueExpression ORing the two things together. This boolean value expression can be passed to a Join or Where clause. If the two parameters cannot be compiled into a BooleanValueExpression, an error is returned.

Types

type DerivedTable

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

DerivedTable describes a subquery in the FROM clause of a SELECT statement.

func NewDerivedTable

func NewDerivedTable(
	name string,
	sel types.Relation,
) *DerivedTable

NewDerivedTable returns a new DerivedTable from the supplied Selection

func (*DerivedTable) Alias

func (t *DerivedTable) Alias() string

Alias returns the alias of the DerivedTable, which is always the DerivedTable's name

func (*DerivedTable) AliasOrName

func (t *DerivedTable) AliasOrName() string

AliasOrName returns the alias of the DerivedTable

func (*DerivedTable) C

func (t *DerivedTable) C(name string) types.Projection

C returns a pointer to a Column with a name matching the supplied string, or nil if no such column is known

The name matching is done using case-insensitive matching, since this is how the SQL standard works for identifiers and symbols (even though Microsoft SQL Server uses case-sensitive identifier names).

func (*DerivedTable) Column

func (t *DerivedTable) Column(name string) types.Projection

Column returns a pointer to a Column with a name or alias matching the supplied string, or nil if no such column is known

func (*DerivedTable) Name

func (t *DerivedTable) Name() string

Name returns the name of the DerivedTable

func (*DerivedTable) Projections

func (t *DerivedTable) Projections() []types.Projection

Projections returns a slice of Projection things referenced by the Selectable. The slice is sorted by the Projection's name.

func (*DerivedTable) QuerySpecification

func (t *DerivedTable) QuerySpecification() *grammar.QuerySpecification

QuerySpecification returns the object as a `*grammar.QuerySpecification`

func (*DerivedTable) TablePrimary

func (t *DerivedTable) TablePrimary() *grammar.TablePrimary

TablePrimary returns the object as a `*grammar.TablePrimary`

func (*DerivedTable) TableReference

func (t *DerivedTable) TableReference() *grammar.TableReference

TableReference returns the object as a `*grammar.TableReference`

type Selection

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

Selection wraps a grammar.QuerySpecification, adding methods to inspect the wrapped query specifications projections/columns.

func Select

func Select(
	items ...interface{},
) *Selection

Select returns a QuerySpecification that produces a SELECT SQL statement for one or more items. Items can be a Table, a Column, a Function, another SELECT query, or even a literal value.

Select panics if sqlb cannot compile the supplied arguments into a valid SELECT SQL query. This is intentional, as we want compile-time failures for invalid SQL construction and we want Select() to be chainable with other Select() calls.

If you are constructing SQL expressions dynamically with user-supplied input, use the `SelectE` function which returns a checkable `error` object.

func SelectE

func SelectE(
	items ...interface{},
) (*Selection, error)

SelectE returns a QuerySpecification that produces a SELECT SQL statement for one or more items. Items can be a Table, a Column, a Function, another SELECT query, or even a literal value.

If sqlb cannot compile the supplied arguments into a valid SELECT SQL query, SelectE returns an error.

func (*Selection) Alias

func (s *Selection) Alias() string

Alias returns the alias of the Selection

func (*Selection) AliasOrName

func (s *Selection) AliasOrName() string

AliasOrName returns the alias of the Selection

func (*Selection) As

func (s *Selection) As(subqueryName string) types.Relation

As returns a Selection as a DerivedTable.

As panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of As() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `AsE` function which returns a checkable `error` object.

func (*Selection) AsE

func (s *Selection) AsE(subqueryName string) (types.Relation, error)

AsE returns a Selection as a DerivedTable. If the Selection has not yet had its query specification set, AsE returns an error.

func (*Selection) C

func (s *Selection) C(name string) types.Projection

C returns a pointer to a Column with a name matching the supplied string, or nil if no such column is known

The name matching is done using case-insensitive matching, since this is how the SQL standard works for identifiers and symbols (even though Microsoft SQL Server uses case-sensitive identifier names).

func (*Selection) Count

func (s *Selection) Count() *Selection

Count applies a SELECT COUNT(*) to the Selection

Count panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of Count() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `CountE` function which returns a checkable `error` object.

func (*Selection) CountE

func (s *Selection) CountE() (*Selection, error)

CountE applies a SELECT COUNT(*) to the Selection and returns the Selection. If the Selection has not had its query specification set, CountE returns an error.

func (*Selection) GroupBy

func (s *Selection) GroupBy(
	cols ...interface{},
) *Selection

GroupBy adapts the Selection to group on the supplied columns, returning the adapted Selection itself to support method chaining.

GroupBy panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of GroupBy() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `GroupByE` function which returns a checkable `error` object.

func (*Selection) GroupByE

func (s *Selection) GroupByE(
	cols ...interface{},
) (*Selection, error)

GroupByE adapts the Selection to group on the supplied columns, returning the adapted Selection itself to support method chaining. If the Selection has not had its query specification set or the supplied parameters cannot be converted to ColumnReferences, WhereE returns an error.

func (*Selection) Having

func (s *Selection) Having(
	exprAny interface{},
) *Selection

Having adapts the Selection with the supplied filtering expression as an aggregate filter (a HAVING clause expression), returning the adapted Selection itself to support method chaining.

Having panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of Having() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `HavingE` function which returns a checkable `error` object.

func (*Selection) HavingE

func (s *Selection) HavingE(
	exprAny interface{},
) (*Selection, error)

HavingE adapts the Selection with the supplied filtering expression as an aggregate filter (a HAVING clause expression), returning the adapted Selection itself to support method chaining. If the Selection has not had its query specification set or the supplied parameters cannot be converted to BooleanValueExpressions, HavingE returns an error.

func (*Selection) Join

func (s *Selection) Join(
	rightAny interface{},
	onAny interface{},
) *Selection

Join adapts the Selection after joining the FromClause's last TableReference to the first parameter which must be convertible to a TableReference.

func (*Selection) Limit

func (s *Selection) Limit(count int) *Selection

Limit applies a LIMIT clause to the Selection (or a TOP N clause for T-SQL variants)

Limit panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of Limit() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `LimitE` function which returns a checkable `error` object.

func (*Selection) LimitE

func (s *Selection) LimitE(count int) (*Selection, error)

LimitE applies a LIMIT clause to the Selection (or a TOP N clause for T-SQL variants). If the Selection has not had its query specification set, LimitE returns an error.

func (*Selection) LimitWithOffset

func (s *Selection) LimitWithOffset(
	count int,
	offset int,
) *Selection

LimitWithOffset applies a LIMIT M OFFSET N clause to the Selection

LimitWithOffset panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of LimitWithOffset() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `LimitWithOffsetE` function which returns a checkable `error` object.

func (*Selection) LimitWithOffsetE

func (s *Selection) LimitWithOffsetE(
	count int,
	offset int,
) (*Selection, error)

LimitWithOffset applies a LIMIT M OFFSET N clause to the Selection. If the Selection has not had its query specification set, LimitWithOffsetE returns an error.

func (*Selection) Name

func (s *Selection) Name() string

func (*Selection) OrderBy

func (s *Selection) OrderBy(
	specAnys ...interface{},
) *Selection

OrderBy adds an ORDER BY to the Selection.

OrderBy panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of OrderBy() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `OrderByE` function which returns a checkable `error` object.

func (*Selection) OrderByE

func (s *Selection) OrderByE(
	specAnys ...interface{},
) (*Selection, error)

OrderBy adds an ORDER BY to the Selection. If the Selection has not had its query specification set or the supplied parameters cannot be converted to ValueExpressions, OrderByE returns an error.

func (*Selection) OuterJoin

func (s *Selection) OuterJoin(
	rightAny interface{},
	onAny interface{},
) *Selection

OuterJoin adapts the Selection after left-joining the FromClause's last TableReference to the first parameter which must be convertible to a TableReference.

func (*Selection) Projections

func (s *Selection) Projections() []types.Projection

Projections returns a slice of Projections referenced by the Selection. The slice is sorted by the Projection's name.

func (*Selection) Query

func (s *Selection) Query() interface{}

Query returns the CursorSpecification if set, otherwise returns the wrapped QuerySpecification.

func (*Selection) QuerySpecification

func (s *Selection) QuerySpecification() *grammar.QuerySpecification

QuerySpecification returns the object as a `*grammar.QuerySpecification`

func (*Selection) TablePrimary

func (s *Selection) TablePrimary() *grammar.TablePrimary

TablePrimary returns the object as a `*grammar.TablePrimary`

func (*Selection) TableReference

func (s *Selection) TableReference() *grammar.TableReference

TableReference returns the object as a `*grammar.TableReference`

func (*Selection) Where

func (s *Selection) Where(
	exprAny interface{},
) *Selection

Where adapts the Selection with a filtering expression, returning the Selection pointer to support method chaining.

Where panics if the Selection has not had a query specification set yet. This is intentional, as we want compile-time failures for invalid SQL construction and we want the result of Where() to be chainable with other Selection methods and be usable as an input to the Select() function.

If you are constructing SQL expressions dynamically with user-supplied input, use the `WhereE` function which returns a checkable `error` object.

func (*Selection) WhereE

func (s *Selection) WhereE(
	exprAny interface{},
) (*Selection, error)

WhereE adapts the Selection with a filtering expression, returning the Selection pointer to support method chaining. If the Selection has not had its query specification set or the supplied parameters cannot be converted to BooleanValueExpressions, WhereE returns an error.

Jump to

Keyboard shortcuts

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