sq package - github.com/bokwoon95/go-structured-query/mysql - Go Packages (original) (raw)

This section is empty.

This section is empty.

This section is empty.

type Assignment interface { AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string) AssertAssignment() }

Assignment is an interface representing an SQL Assignment 'Field = Value'.

type Assignments []Assignment

Assignments is a list of Assignments.

AppendSQLExclude marshals the Assignments into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

type BaseQuery struct { DB DB Log Logger LogFlag LogFlag CTEs []CTE }

BaseQuery is a common query builder that can transform into a SelectQuery, InsertQuery, UpdateQuery or DeleteQuery depending on the method that you call on it.

func With(CTEs ...CTE) BaseQuery

With creates a new BaseQuery with the CTEs.

func WithDB(db DB) BaseQuery

WithDB creates a new BaseQuery with the DB.

func WithDefaultLog(flag LogFlag) BaseQuery

WithDefaultLog creates a new BaseQuery with the default logger and the LogFlag

func (q BaseQuery) DeleteFrom(tables ...BaseTable) DeleteQuery

DeleteFrom transforms the BaseQuery into a DeleteQuery.

func (q BaseQuery) From(table Table) SelectQuery

From transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) InsertIgnoreInto(table BaseTable) InsertQuery

InsertIgnoreInto transforms the BaseQuery into an InsertQuery.

func (q BaseQuery) InsertInto(table BaseTable) InsertQuery

InsertInto transforms the BaseQuery into an InsertQuery.

func (q BaseQuery) Select(fields ...Field) SelectQuery

Select transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) SelectAll() SelectQuery

SelectAll transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) SelectCount() SelectQuery

SelectCount transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) SelectDistinct(fields ...Field) SelectQuery

SelectDistinct transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) SelectOne() SelectQuery

SelectOne transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) SelectRowx(mapper func(*Row)) SelectQuery

SelectRowx transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) Selectx(mapper func(*Row), accumulator func()) SelectQuery

Selectx transforms the BaseQuery into a SelectQuery.

func (q BaseQuery) Union(queries ...Query) VariadicQuery

Union transforms the BaseQuery into a VariadicQuery.

func (q BaseQuery) UnionAll(queries ...Query) VariadicQuery

UnionAll transforms the BaseQuery into a VariadicQuery.

func (q BaseQuery) Update(table BaseTable) UpdateQuery

Update transforms the BaseQuery into an UpdateQuery.

func (q BaseQuery) With(CTEs ...CTE) BaseQuery

With adds the CTEs to the BaseQuery

func (q BaseQuery) WithDB(db DB) BaseQuery

WithDB adds the DB to the BaseQuery.

func (q BaseQuery) WithDefaultLog(flag LogFlag) BaseQuery

WithDefaultLog adds the default logger and the LogFlag to the BaseQuery.

type BaseTable interface { Table AssertBaseTable() }

BaseTable is an interface that specialises the Table interface. It covers only tables/views that exist in the database.

type BinaryField struct {

}

BinaryField either represents a BLOB column or a literal []byte value.

Bytes returns a new BinaryField representing a literal []byte value.

func NewBinaryField(name string, table Table) BinaryField

NewBinaryField returns a new BinaryField representing a BLOB column.

AppendSQLExclude marshals the BinaryField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.

GetAlias returns the alias of the BinaryField.

GetName returns the name of the BinaryField.

func (f BinaryField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (f BinaryField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (f BinaryField) Set(v interface{}) FieldAssignment

Set returns a FieldAssignment associating the BinaryField to the value i.e. 'field = value'.

SetBytes returns a FieldAssignment associating the BinaryField to the int value i.e. 'field = value'.

type BooleanField struct {

}

BooleanField either represents a boolean column or a literal bool value.

Bool returns a new Boolean Field representing a literal bool value.

func NewBooleanField(name string, table Table) BooleanField

NewBooleanField returns a new BooleanField representing a boolean column.

AppendSQLExclude marshals the BooleanField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.

As aliases the BooleanField i.e. 'field AS Alias'.

func (f BooleanField) Asc() BooleanField

Asc returns a new BooleanField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (f BooleanField) Desc() BooleanField

Desc returns a new BooleanField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (f BooleanField) Eq(field BooleanField) Predicate

Eq returns an 'X = Y' Predicate. It only accepts BooleanField.

GetAlias returns the alias of the BooleanField.

GetName returns the name of the BooleanField.

func (f BooleanField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (f BooleanField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (f BooleanField) Ne(field BooleanField) Predicate

Ne returns an 'X <> Y' Predicate. It only accepts BooleanField.

func (f BooleanField) Not() Predicate

Not inverts the BooleanField i.e. 'NOT BooleanField'.

func (f BooleanField) Set(val interface{}) FieldAssignment

Set returns a FieldAssignment associating the BooleanField to the value i.e. 'field = value'.

SetBool returns a FieldAssignment associating the BooleanField to the bool value i.e. 'field = value'.

String returns the string representation of the BooleanField.

CTE represents an SQL CTE.

RecursiveCTE constructs a new recursive CTE.

AppendSQL marshals the CTE into a buffer and args slice.

As returns a new CTE with the alias i.e. 'CTE AS alias'.

GetAlias returns the alias of the CTE.

func (CTE) GetColumns added in v0.2.0

func (cte CTE) GetColumns() []string

GetColumns returns the CTE's columns.

GetName returns the name of the CTE.

func (cte CTE) GetQuery() Query

GetQuery returns the CTE's underlying Query.

func (cte *CTE) Initial(query Query) IntermediateCTE

Initial specifies recursive CTE's initial query. If the CTE is not recursive, this operation is a no-op.

func (cte CTE) IsRecursive() bool

IsRecursive checks if the CTE is recursive.

type Column added in v0.4.0

Column keeps track of what the values mapped to what Field in an InsertQuery/SelectQuery.

func (*Column) Set added in v0.4.0

func (col *Column) Set(field Field, value interface{})

Set maps the value to the Field.

func (*Column) SetBool added in v0.4.0

func (col *Column) SetBool(field BooleanField, value bool)

SetBool maps the bool value to the BooleanField.

func (*Column) SetFloat64 added in v0.4.0

func (col *Column) SetFloat64(field NumberField, value float64)

SetFloat64 maps the float64 value to the NumberField.

func (*Column) SetInt added in v0.4.0

func (col *Column) SetInt(field NumberField, value int)

SetInt maps the int value to the NumberField.

func (*Column) SetInt64 added in v0.4.0

func (col *Column) SetInt64(field NumberField, value int64)

SetInt64 maps the int64 value to the NumberField.

func (*Column) SetString added in v0.4.0

func (col *Column) SetString(field StringField, value string)

SetString maps the string value to the StringField.

func (*Column) SetTime added in v0.4.0

SetTime maps the time.Time value to the TimeField.

type CustomAssignment struct { Format string Values []interface{} }

CustomAssignment is an Assignment that can render itself in an arbitrary way by calling expandValues on its Format and Values.

AppendSQLExclude marshals the CustomAssignment into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

func (set CustomAssignment) AssertAssignment()

AssertAssignment implements the Assignment interface.

type CustomField struct { Alias string Format string Values []interface{} IsDesc *bool }

CustomField is a Field that can render itself in an arbitrary way by calling expandValues on its Format and Values.

func Fieldf(format string, values ...interface{}) CustomField

Fieldf creates a new CustomField.

func FirstValueOver(field interface{}, window Window) CustomField

FirstValueOver represents the FIRST_VALUE(field) OVER window function.

func LagOver(field interface{}, offset interface{}, fallback interface{}, window Window) CustomField

LagOver represents the LAG(field, offset, fallback) OVER window function.

func LastValueOver(field interface{}, window Window) CustomField

LastValueOver represents the LAST_VALUE(field) OVER window function.

func LeadOver(field interface{}, offset interface{}, fallback interface{}, window Window) CustomField

LeadOver represents the LEAD(field, offset, fallback) OVER window function.

func NthValueOver(field interface{}, n int, window Window) CustomField

NthValueOver represents the NTH_VALUE(field, n) OVER window function.

func Values(field Field) CustomField

Values wraps a field to simulate the VALUES(field) MySQL construct for the ON DUPLICATE KEY UPDATE clause.

AppendSQLExclude marshals the CustomField into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

As aliases the CustomField i.e. 'field AS Alias'.

func (f CustomField) Asc() CustomField

Asc returns a new CustomField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (f CustomField) Desc() CustomField

Desc returns a new CustomField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (f CustomField) Eq(v interface{}) Predicate

Eq returns an 'X = Y' Predicate.

func (f CustomField) Ge(v interface{}) Predicate

Ge returns an 'X >= Y' Predicate.

GetAlias returns the alias of the CustomField.

GetName returns the name of the CustomField.

func (f CustomField) Gt(v interface{}) Predicate

Gt returns an 'X > Y' Predicate.

func (f CustomField) In(v interface{}) Predicate

In returns an 'X IN (Y)' Predicate.

func (f CustomField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (f CustomField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (f CustomField) Le(v interface{}) Predicate

Le returns an 'X <= Y' Predicate.

func (f CustomField) Lt(v interface{}) Predicate

Lt returns an 'X < Y' Predicate.

func (f CustomField) Ne(v interface{}) Predicate

Ne returns an 'X <> Y' Predicate.

String returns the string representation of the CustomField.

type CustomPredicate struct { Alias string Format string Values []interface{} Negative bool }

CustomPredicate is a Query that can render itself in an arbitrary way by calling expandValues on its Format and Values.

func Exists(query Query) CustomPredicate

Exists represents the EXISTS() predicate.

func Predicatef(format string, values ...interface{}) CustomPredicate

Predicatef creates a new CustomPredicate.

AppendSQLExclude marshals the CustomPredicate into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

As aliases the CustomPredicate.

GetAlias returns the alias of the CustomPredicate.

GetName returns the name of the CustomPredicate, which is always an empty string.

func (p CustomPredicate) Not() Predicate

Not inverts the CustomPredicate i.e. 'NOT CustomPredicate'.

type DB interface { Query(query string, args ...interface{}) (sql.Rows, error) QueryContext(ctx context.Context, query string, args ...interface{}) (sql.Rows, error) Exec(query string, args ...interface{}) (sql.Result, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) }

DB is an interface providing database querying abilities.

type DeleteQuery struct { Alias string

CTEs [][CTE](#CTE)

FromTables [][BaseTable](#BaseTable)

UsingTable [Table](#Table)
JoinTables [JoinTables](#JoinTables)

WherePredicate [VariadicPredicate](#VariadicPredicate)

OrderByFields [Fields](#Fields)

LimitValue *[int64](/builtin#int64)

DB [DB](#DB)

Log     [Logger](#Logger)
LogFlag [LogFlag](#LogFlag)

}

DeleteQuery represents a DELETE query.

func DeleteFrom(tables ...BaseTable) DeleteQuery

DeleteFrom creates a new DeleteQuery.

AppendSQL marshals the DeleteQuery into a buffer and args slice.

func (q DeleteQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) DeleteQuery

CustomJoin custom joins a table to the DeleteQuery. The join type can be specified with a string, e.g. "CROSS JOIN".

func (q DeleteQuery) DeleteFrom(tables ...BaseTable) DeleteQuery

DeleteFrom adds new tables to delete from to the DeleteQuery.

Exec will execute the DeleteQuery with the given DB. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.

ExecContext will execute the DeleteQuery with the given DB and context. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.

func (q DeleteQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery

FullJoin full joins a table to the DeleteQuery based on the predicates.

func (q DeleteQuery) Join(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery

Join joins a new table to the DeleteQuery based on the predicates.

func (q DeleteQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery

LeftJoin left joins a new table to the DeleteQuery based on the predicates.

func (q DeleteQuery) Limit(limit int) DeleteQuery

Limit sets the limit in the DeleteQuery.

func (q DeleteQuery) NestThis() Query

NestThis indicates to the DeleteQuery that it is nested.

func (q DeleteQuery) OrderBy(fields ...Field) DeleteQuery

OrderBy appends the fields to the ORDER BY clause in the DeleteQuery.

func (q DeleteQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery

RightJoin right joins a new table to the DeleteQuery based on the predicates.

func (q DeleteQuery) ToSQL() (string, []interface{})

ToSQL marshals the DeleteQuery into a query string and args slice.

func (q DeleteQuery) Using(table Table) DeleteQuery

Using adds a new table to the DeleteQuery.

func (q DeleteQuery) Where(predicates ...Predicate) DeleteQuery

Where appends the predicates to the WHERE clause in the DeleteQuery.

func (q DeleteQuery) With(ctes ...CTE) DeleteQuery

With appends the CTEs into the DeleteQuery.

type EnumField = StringField

EnumField is a type alias for StringField.

func NewEnumField(name string, table Table) EnumField

NewEnumField returns an EnumField representing an enum column.

ExecFlag is a flag that affects the behavior of Exec.

const ( ElastInsertID ExecFlag = 1 << iota ErowsAffected )

ExecFlags

ExitCode represents a reason for terminating the rows.Next() loop.

const ( ExitPeacefully ExitCode = iota )

ExitCodes

Error implements the error interface.

Field is an interface that represents either a Table column or an SQL value.

type FieldAssignment struct { Field Field Value interface{} }

FieldAssignment represents a Field and Value set. Its usage appears in both the UPDATE and INSERT queries whenever values are assigned to columns e.g. 'field = value'.

AppendSQLExclude marshals the FieldAssignment into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

func (set FieldAssignment) AssertAssignment()

AssertAssignment implements the Assignment interface.

FieldLiteral is a Field where its underlying string is literally plugged into the SQL query.

AppendSQLExclude marshals the FieldLiteral into a buffer and an args slice.

GetAlias returns the alias of the FieldLiteral, which is always an empty string.

GetName returns the FieldLiteral's underlying string.

Fields represents the "field1, field2, etc..." SQL construct.

AppendSQLExclude marshals PredicateCases into a buffer and an args slice. It propagates the excludedTableQualifiers down to its Fields.

AppendSQLExcludeWithAlias is exactly like AppendSQLExclude, but appends each field (i.e. field1 AS alias1, field2 AS alias2, ...) with its alias if it has one.

type InsertQuery struct { Alias string

Ignore        [bool](/builtin#bool)
IntoTable     [BaseTable](#BaseTable)
InsertColumns [Fields](#Fields)

RowValues [RowValues](#RowValues)

SelectQuery *[SelectQuery](#SelectQuery)

Resolution [Assignments](#Assignments)

DB           [DB](#DB)
ColumnMapper func(*[Column](#Column))

Log     [Logger](#Logger)
LogFlag [LogFlag](#LogFlag)

}

InsertQuery represents an INSERT query.

func InsertIgnoreInto(table BaseTable) InsertQuery

InsertIgnoreInto creates a new InsertQuery.

func InsertInto(table BaseTable) InsertQuery

InsertInto creates a new InsertQuery.

AppendSQL marshals the InsertQuery into a buffer and args slice. Do not call this as an end user, use ToSQL instead. AppendSQL may panic if you wrote panic code in your ColumnMapper, it is only exported to satisfy the Query interface.

func (InsertQuery) Columns

func (q InsertQuery) Columns(fields ...Field) InsertQuery

Columns sets the insert columns for the InsertQuery.

func (q InsertQuery) Exec(db DB, flag ExecFlag) (lastInsertID, rowsAffected int64, err error)

Exec will execute the InsertQuery with the given DB. It will only compute the lastInsertID if the ElastInsertID ExecFlag is passed to it. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it. To compute both, bitwise or the flags together i.e. ElastInsertID|ErowsAffected.

ExecContext will execute the InsertQuery with the given DB and context. It will only compute the lastInsertID if the ElastInsertID ExecFlag is passed to it. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it. To compute both, bitwise or the flags together i.e. ElastInsertID|ErowsAffected.

func (q InsertQuery) InsertIgnoreInto(table BaseTable) InsertQuery

InsertIgnoreInto sets the insert table for the InsertQuery.

func (q InsertQuery) InsertInto(table BaseTable) InsertQuery

InsertInto sets the insert table for the InsertQuery.

func (q InsertQuery) NestThis() Query

NestThis indicates to the InsertQuery that it is nested.

func (q InsertQuery) OnDuplicateKeyUpdate(assignments ...Assignment) InsertQuery

OnDuplicateKeyUpdate sets the assignments done on duplicate key for the InsertQuery.

func (q InsertQuery) Select(selectQuery SelectQuery) InsertQuery

Select adds a SelectQuery to the InsertQuery.

func (q InsertQuery) ToSQL() (query string, args []interface{})

ToSQL marshals the InsertQuery into a query string and args slice.

func (q InsertQuery) Values(values ...interface{}) InsertQuery

Values appends a new RowValue to the InsertQuery.

func (q InsertQuery) Valuesx(mapper func(*Column)) InsertQuery

Valuesx sets the column mapper for the InsertQuery.

IntermediateCTE is a CTE used to hold the intermediate state of a recursive CTE just after the CTE's initial query is declared. It can only be converted back into a CTE by adding the recursive queries that UNION into the CTE.

func (cte IntermediateCTE) Union(queries ...Query) CTE

Union specifies the queries to be UNIONed into the CTE. If the CTE is not recursive, this operation is a no-op.

func (cte IntermediateCTE) UnionAll(queries ...Query) CTE

UnionAll specifies the queries to be UNION-ALLed into the CTE. If the CTE is not recursive, this operation is a no-op.

type JSONField struct {

}

JSONField either represents a JSON column or a literal value that can be marshalled into a JSON string.

func JSON(val interface{}) (JSONField, error)

JSON returns a new JSONField representing a literal JSONable value. It returns an error indicating if the value can be marshalled into JSON.

JSONValue returns a new JSONField representing a driver.Valuer value.

func MustJSON(val interface{}) JSONField

MustJSON is like JSON but it panics on error.

func NewJSONField(name string, table Table) JSONField

NewJSONField returns a new JSONField representing a JSON column.

AppendSQLExclude marshals the JSONField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.

As aliases the JSONField i.e. 'field AS Alias'.

func (f JSONField) Asc() JSONField

Asc returns a new JSONField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (f JSONField) Desc() JSONField

Desc returns a new JSONField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

GetAlias returns the Alias of the JSONField.

GetName returns the Name of the JSONField.

func (f JSONField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (f JSONField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (f JSONField) Set(value interface{}) FieldAssignment

Set returns a FieldAssignment associating the JSONField to the value i.e. 'field = value'.

func (f JSONField) SetJSON(value interface{}) FieldAssignment

SetJSON returns a FieldAssignment associating the JSONField to the JSONable value i.e. 'field = value'. Internally it uses MustJSON, which means it will panic if the value cannot be marshalled into JSON.

SetValue returns a FieldAssignment associating the JSONField to the driver.Valuer value i.e. 'field = value'.

String returns the string representation of the JSONField.

type JoinTable struct { JoinType JoinType Table Table OnPredicates VariadicPredicate }

JoinTable represents an SQL join.

func CustomJoin(joinType JoinType, table Table, predicates ...Predicate) JoinTable

CustomJoin creates a custom join. The join type can be specified with a string, e.g. "CROSS JOIN".

func FullJoin(table Table, predicates ...Predicate) JoinTable

FullJoin creates a new full join.

func Join(table Table, predicates ...Predicate) JoinTable

Join creates a new inner join.

func LeftJoin(table Table, predicates ...Predicate) JoinTable

LeftJoin creates a new left join.

func RightJoin(table Table, predicates ...Predicate) JoinTable

RightJoin creates a new right join.

AppendSQL marshals the JoinTable into a buffer and an args slice.

type JoinTables []JoinTable

JoinTables is a list of JoinTables.

AppendSQL marshals the JoinTables into a buffer and an args slice.

JoinType represents the various types of SQL joins.

const ( JoinTypeInner JoinType = "JOIN" JoinTypeLeft JoinType = "LEFT JOIN" JoinTypeRight JoinType = "RIGHT JOIN" JoinTypeFull JoinType = "FULL JOIN" )

JoinTypes

LogFlag is a flag that affects the verbosity of the Logger output.

const ( Linterpolate LogFlag = 1 << iota Lstats Lresults

Lverbose = [Lstats](#Lstats) | [Lresults](#Lresults)

)

LogFlags

Logger is an interface that provides logging.

type NumberField struct {

}

NumberField either represents a number column, a number expression or a literal number value.

func Avg(field interface{}) NumberField

Avg represents the AVG() aggregate function.

func AvgOver(field interface{}, window Window) NumberField

AvgOver represents the AVG() OVER window function.

Count represents the COUNT(*) aggregate function.

func CountOver(window Window) NumberField

CountOver represents the COUNT(*) OVER window function.

func CumeDistOver(window Window) NumberField

CumeDistOver represents the CUME_DIST() OVER window function.

func DenseRankOver(window Window) NumberField

DenseRankOver represents the DENSE_RANK() OVER window function.

Float64 returns a new NumberField representing a literal float64 value.

Int returns a new NumberField representing a literal int value.

Int64 returns a new NumberField representing a literal int64 value.

func Max(field interface{}) NumberField

Max represents the MAX() aggregate function.

func MaxOver(field interface{}, window Window) NumberField

MaxOver represents the MAX() OVER window function.

func Min(field interface{}) NumberField

Min represents the MIN() aggregate function.

func MinOver(field interface{}, window Window) NumberField

MinOver represents the MIN() OVER window function.

func NewNumberField(name string, table Table) NumberField

NewNumberField returns a new NumberField representing a number TableInfo column.

func NtileOver(n int, window Window) NumberField

NtileOver represents the NTILE(n) OVER window function.

func NumberFieldf(format string, values ...interface{}) NumberField

NumberFieldf creates a new number expression.

func PercentRankOver(window Window) NumberField

PercentRankOver represents the PERCENT_RANK() OVER window function.

func RankOver(window Window) NumberField

RankOver represents the RANK() OVER window function.

func RowNumberOver(window Window) NumberField

RowNumberOver represents the ROW_NUMBER() OVER window function.

func Sum(field interface{}) NumberField

Sum represents the SUM() aggregate function.

func SumOver(field interface{}, window Window) NumberField

SumOver represents the SUM() OVER window function.

AppendSQLExclude marshals the NumberField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.

As aliases the NumberField i.e. 'field AS Alias'.

func (f NumberField) Asc() NumberField

Asc returns a new NumberField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (f NumberField) Desc() NumberField

Desc returns a new NumberField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (f NumberField) Eq(field NumberField) Predicate

Eq returns an 'X = Y' Predicate. It only accepts NumberField.

EqFloat64 returns an 'X = Y' Predicate. It only accepts float64.

func (f NumberField) EqInt(num int) Predicate

EqInt returns an 'X = Y' Predicate. It only accepts int.

func (f NumberField) Ge(field NumberField) Predicate

Ge returns an 'X >= Y' Predicate. It only accepts NumberField.

GeFloat64 returns an 'X >= Y' Predicate. It only accepts float64.

func (f NumberField) GeInt(num int) Predicate

GeInt returns an 'X >= Y' Predicate. It only accepts int.

GetAlias returns the alias of the NumberField.

GetName returns the name of the NumberField.

func (f NumberField) Gt(field NumberField) Predicate

Gt returns an 'X > Y' Predicate. It only accepts NumberField.

GtFloat64 returns an 'X > Y' Predicate. It only accepts float64.

func (f NumberField) GtInt(num int) Predicate

GtInt returns an 'X > Y' Predicate. It only accepts int.

func (f NumberField) In(v interface{}) Predicate

In returns an 'X IN (Y)' Predicate.

func (f NumberField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (f NumberField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (f NumberField) Le(field NumberField) Predicate

Le returns an 'X <= Y' Predicate. It only accepts NumberField.

LeFloat64 returns an 'X <= Y' Predicate. It only accepts float64.

func (f NumberField) LeInt(num int) Predicate

LeInt returns an 'X <= Y' Predicate. It only accepts int.

func (f NumberField) Lt(field NumberField) Predicate

Lt returns an 'X < Y' Predicate. It only accepts NumberField.

LtFloat64 returns an 'X < Y' Predicate. It only accepts float64.

func (f NumberField) LtInt(num int) Predicate

LtInt returns an 'X < Y' Predicate. It only accepts int.

func (f NumberField) Ne(field NumberField) Predicate

Ne returns an 'X <> Y' Predicate. It only accepts NumberField.

NeFloat64 returns an 'X <> Y' Predicate. It only accepts float64.

func (f NumberField) NeInt(num int) Predicate

NeInt returns an 'X <> Y' Predicate. It only accepts int.

func (f NumberField) Set(val interface{}) FieldAssignment

Set returns a FieldAssignment associating the NumberField to the value i.e. 'field = value'.

SetFloat64 returns a FieldAssignment associating the NumberField to the float64 value i.e. 'field = value'.

SetInt returns a FieldAssignment associating the NumberField to the int value i.e. 'field = value'.

SetInt64 returns a FieldAssignment associating the NumberField to the int64 value i.e. 'field = value'.

String returns the string representation of the NumberField.

type Predicate interface { Field Not() Predicate }

Predicate is an interface that evaluates to true or false in SQL.

func Eq(f1, f2 interface{}) Predicate

Eq returns an 'X = Y' Predicate.

func Ge(f1, f2 interface{}) Predicate

Ge returns an 'X >= Y' Predicate.

func Gt(f1, f2 interface{}) Predicate

Gt returns an 'X > Y' Predicate.

func In(f1 interface{}, f2 []interface{}) Predicate

In returns an 'X IN (Y)' Predicate.

func Le(f1, f2 interface{}) Predicate

Le returns an 'X <= Y' Predicate.

func Lt(f1, f2 interface{}) Predicate

Lt returns an 'X < Y' Predicate.

func Ne(f1, f2 interface{}) Predicate

Ne returns an 'X <> Y' Predicate.

func Not(predicate Predicate) Predicate

Not inverts the Predicate i.e. 'NOT Predicate'.

type PredicateCase struct { Condition Predicate Result interface{} }

PredicateCase represents a Predicate and the Result if the Predicate is true.

type PredicateCases struct { Alias string Cases []PredicateCase Fallback interface{} }

PredicateCases is the general form of the CASE expression.

func CaseWhen(predicate Predicate, result interface{}) PredicateCases

CaseWhen creates a new PredicateCases i.e. CASE WHEN X THEN Y.

AppendSQLExclude marshals the PredicateCases into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

As aliases the PredicateCases.

func (f PredicateCases) Else(fallback interface{}) PredicateCases

Else adds the fallback value for the PredicateCases i.e. ELSE X.

GetAlias returns the alias of the PredicateCases.

GetName returns the name of the PredicateCases, which is always an empty string.

func (f PredicateCases) When(predicate Predicate, result interface{}) PredicateCases

When adds a new PredicateCase to the PredicateCases i.e. WHEN X THEN Y.

Query is an interface that specialises the Table interface. It covers only queries like SELECT/INSERT/UPDATE/DELETE.

Row represents the state of a row after a call to rows.Next().

func (r *Row) Bool(predicate Predicate) bool

Bool returns the bool value of the Predicate. BooleanFields are considered predicates, so you can use them here.

func (r *Row) BoolValid(predicate Predicate) bool

BoolValid returns the bool value indicating if the Predicate is non-NULL. BooleanFields are considered Predicates, so you can use them here.

Float64 returns the float64 value of the NumberField.

func (r *Row) Float64Valid(field NumberField) bool

Float64Valid returns the bool value indicating if the NumberField is non-NULL.

func (r *Row) Int(field NumberField) int

Int returns the int value of the NumberField.

Int64 returns the int64 value of the NumberField.

func (r *Row) Int64Valid(field NumberField) bool

Int64Valid returns the bool value indicating if the NumberField is non-NULL.

func (r *Row) IntValid(field NumberField) bool

IntValid returns the bool value indicating if the NumberField is non-NULL.

NullBool returns the sql.NullBool value of the Predicate.

NullFloat64 returns the sql.NullFloat64 value of the NumberField.

NullInt64 returns the sql.NullInt64 value of the NumberField.

NullString returns the sql.NullString value of the StringField.

NullTime returns the sql.NullTime value of the TimeField.

func (r *Row) ScanInto(dest interface{}, field Field)

ScanInto scans the field into a dest, where dest is a pointer.

String returns the string value of the StringField.

func (r *Row) StringValid(field StringField) bool

StringValid returns the bool value indicating if the StringField is non-NULL.

Time returns the time.Time value of the TimeField.

func (r *Row) TimeValid(field TimeField) bool

TimeValid returns a bool value indicating if the TimeField is non-NULL.

type RowValue []interface{}

RowValue represents an SQL Row Value Expression i.e. (a, b, c...)

AppendSQL marshals the RowValue into a buffer and an args slice.

AppendSQLExclude marshals the RowValue into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

func (r RowValue) In(v interface{}) CustomPredicate

In returns an 'X IN (Y)' Predicate.

func (r RowValue) Set(v interface{}) CustomAssignment

Set returns an Assignment assigning v to the RowValue.

type RowValues []RowValue

RowValues represents a list of RowValues i.e. (a, b, c...), (d, e, f...), (g, h, i...)

AppendSQL marshals the RowValues into a buffer and an args slice.

type SelectQuery struct { Alias string

CTEs [][CTE](#CTE)

SelectType   [SelectType](#SelectType)
SelectFields [Fields](#Fields)

FromTable  [Table](#Table)
JoinTables [JoinTables](#JoinTables)

WherePredicate [VariadicPredicate](#VariadicPredicate)

GroupByFields [Fields](#Fields)

HavingPredicate [VariadicPredicate](#VariadicPredicate)

Windows [Windows](#Windows)

OrderByFields [Fields](#Fields)

LimitValue *[int64](/builtin#int64)

OffsetValue *[int64](/builtin#int64)

DB          [DB](#DB)
RowMapper   func(*[Row](#Row))
Accumulator func()

Log     [Logger](#Logger)
LogFlag [LogFlag](#LogFlag)

}

SelectQuery represents a SELECT query.

func From(table Table) SelectQuery

From creates a new SelectQuery.

func Select(fields ...Field) SelectQuery

Select creates a new SelectQuery.

func SelectDistinct(fields ...Field) SelectQuery

SelectDistinct creates a new SelectQuery.

func SelectOne() SelectQuery

SelectOne creates a new SelectQuery.

func SelectRowx(mapper func(*Row)) SelectQuery

SelectRowx creates a new SelectQuery.

func Selectx(mapper func(*Row), accumulator func()) SelectQuery

Selectx creates a new SelectQuery.

AppendSQL marshals the SelectQuery into a buffer and args slice.

CTE converts a SelectQuery into a CTE.

func (q SelectQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) SelectQuery

CustomJoin custom joins a table to the SelectQuery. The join type can be specified with a string, e.g. "CROSS JOIN".

func (q SelectQuery) Fetch(db DB) (err error)

Fetch will run SelectQuery with the given DB. It then maps the results based on the mapper function (and optionally runs the accumulator function).

FetchContext will run SelectQuery with the given DB and context. It then maps the results based on the mapper function (and optionally runs the accumulator function).

func (q SelectQuery) From(table Table) SelectQuery

From sets the table in the SelectQuery.

func (q SelectQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery

FullJoin full joins a table to the SelectQuery based on the predicates.

func (q SelectQuery) GroupBy(fields ...Field) SelectQuery

GroupBy appends the fields to the GROUP BY clause in the SelectQuery.

func (q SelectQuery) Having(predicates ...Predicate) SelectQuery

Having appends the predicates to the HAVING clause in the SelectQuery.

func (q SelectQuery) Join(table Table, predicate Predicate, predicates ...Predicate) SelectQuery

Join joins a new table to the SelectQuery based on the predicates.

func (q SelectQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery

LeftJoin left joins a new table to the SelectQuery based on the predicates.

func (q SelectQuery) Limit(limit int) SelectQuery

Limit sets the limit in the SelectQuery.

func (q SelectQuery) NestThis() Query

NestThis indicates to the SelectQuery that it is nested.

func (q SelectQuery) Offset(offset int) SelectQuery

Offset sets the offset in the SelectQuery.

func (q SelectQuery) OrderBy(fields ...Field) SelectQuery

OrderBy appends the fields to the ORDER BY clause in the SelectQuery.

func (q SelectQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery

RightJoin right joins a new table to the SelectQuery based on the predicates.

func (q SelectQuery) Select(fields ...Field) SelectQuery

Select adds the fields to the SelectFields in the SelectQuery.

func (q SelectQuery) SelectAll() SelectQuery

SelectAll sets the SELECT clause to SELECT *.

func (q SelectQuery) SelectCount() SelectQuery

SelectCount sets the SELECT clause to SELECT COUNT(*).

func (q SelectQuery) SelectDistinct(fields ...Field) SelectQuery

SelectDistinct adds the fields to the SelectFields in the SelectQuery.

func (q SelectQuery) SelectOne() SelectQuery

SelectOne sets the SELECT clause to SELECT 1.

func (q SelectQuery) SelectRowx(mapper func(*Row)) SelectQuery

SelectRowx sets the mapper function in the SelectQuery.

func (q SelectQuery) Selectx(mapper func(*Row), accumulator func()) SelectQuery

Selectx sets the mapper function and accumulator function in the SelectQuery.

Subquery converts a SelectQuery into a Subquery.

func (q SelectQuery) ToSQL() (string, []interface{})

ToSQL marshals the SelectQuery into a query string and args slice.

func (q SelectQuery) Where(predicates ...Predicate) SelectQuery

Where appends the predicates to the WHERE clause in the SelectQuery.

func (q SelectQuery) Window(windows ...Window) SelectQuery

Window appends the windows to the WINDOW clause in the SelectQuery.

func (q SelectQuery) With(ctes ...CTE) SelectQuery

With appends a list of CTEs into the SelectQuery.

SelectType represents the various SQL selects.

const ( SelectTypeDefault SelectType = "SELECT" SelectTypeDistinct SelectType = "SELECT DISTINCT" )

SelectTypes

type SimpleCase struct { Value interface{} Result interface{} }

SimpleCase represents a Value to be compared against and the Result if it matches.

type SimpleCases struct { Alias string Expression interface{} Cases []SimpleCase Fallback interface{} }

SimpleCases is the simple form of the CASE expression.

func Case(field Field) SimpleCases

Case creates a new SimpleCases i.e. CASE X

AppendSQLExclude marshals the SimpleCases into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

As aliases the SimpleCases.

func (f SimpleCases) Else(field Field) SimpleCases

Else adds the fallback value for the SimpleCases i.e. ELSE X.

GetAlias returns the alias of the SimpleCases.

GetName returns the name of the simple cases, which is always an empty string.

func (f SimpleCases) When(field Field, result Field) SimpleCases

When adds a new SimpleCase to the SimpleCases i.e. WHEN X THEN Y.

type StringField struct {

}

StringField either represents a string column or a literal string value.

func NewStringField(name string, table Table) StringField

NewStringField returns a new StringField representing a boolean column.

String returns a new StringField representing a literal string value.

AppendSQLExclude marshals the StringField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.

As returns a new StringField with the new field Alias i.e. 'field AS Alias'.

func (f StringField) Asc() StringField

Asc returns a new StringField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (f StringField) Desc() StringField

Desc returns a new StringField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (f StringField) Eq(field StringField) Predicate

Eq returns an 'X = Y' Predicate. It only accepts StringField.

EqString returns an 'X = Y' Predicate. It only accepts string.

func (f StringField) Ge(field StringField) Predicate

Ge returns an 'X >= Y' Predicate. It only accepts StringField.

GeString returns an 'X >= Y' Predicate. It only accepts string.

GetAlias returns the alias of the StringField.

GetName returns the name of the StringField.

func (f StringField) Gt(field StringField) Predicate

Gt returns an 'X > Y' Predicate. It only accepts StringField.

GtString returns an 'X > Y' Predicate. It only accepts string.

func (f StringField) In(v interface{}) Predicate

In returns an 'X IN (Y)' Predicate.

func (f StringField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (f StringField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (f StringField) Le(field StringField) Predicate

Le returns an 'X <= Y' Predicate. It only accepts StringField.

LeString returns an 'X <= Y' Predicate. It only accepts string.

LikeString returns an 'A LIKE B' Predicate. It only accepts string.

func (f StringField) Lt(field StringField) Predicate

Lt returns an 'X < Y' Predicate. It only accepts StringField.

LtString returns an 'X < Y' Predicate. It only accepts string.

func (f StringField) Ne(field StringField) Predicate

Ne returns an 'X <> Y' Predicate. It only accepts StringField.

NeString returns an 'X <> Y' Predicate. It only accepts string.

NotLikeString returns an 'A NOT LIKE B' Predicate. It only accepts string.

func (f StringField) Set(value interface{}) FieldAssignment

Set returns a FieldAssignment associating the StringField to the value i.e. 'field = value'.

SetString returns a FieldAssignment associating the StringField to the string value i.e. 'field = value'.

String returns the string representation of the StringField.

Subquery represents an SQL subquery.

AppendSQL marshals the Subquery into a buffer and args slice.

GetAlias returns the alias of the Subquery.

GetName returns the name of the Subquery.

func (subq Subquery) GetQuery() Query

GetQuery returns the Subquery's underlying Query.

func (subq Subquery) NestThis() Query

NestThis indicates to the Subquery that it is nested.

func (subq Subquery) ToSQL() (string, []interface{})

ToSQL marshals the Subquery into a query string and args slice.

Table is an interface representing anything that you can SELECT FROM or JOIN.

TableInfo is struct that implements the Table interface, containing all the information needed to call itself a Table. It is meant to be embedded in arbitrary structs to also transform them into valid Tables.

AppendSQL marshals the TableInfo into a buffer and an args slice.

func (tbl *TableInfo) AssertBaseTable()

AssertBaseTable implements the BaseTable interface.

GetAlias returns the alias of the TableInfo.

GetName returns the name of the TableInfo.

type TimeField struct {

}

TimeField either represents a time column or a literal time.Time value.

func NewTimeField(name string, table Table) TimeField

NewTimeField returns a new TimeField representing a time column.

Time returns a new TimeField representing a literal time.Time value.

AppendSQLExclude marshals the TimeField into an SQL query and args as described in the TimeField internal struct comments.

As returns a new TimeField with the new field Alias i.e. 'field AS Alias'.

func (f TimeField) Asc() TimeField

Asc returns a new TimeField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.

func (f TimeField) Between(start, end TimeField) Predicate

Between returns an 'X BETWEEN Y AND Z' Predicate. It only accepts TimeField.

BetweenTime returns an 'X BETWEEN Y AND Z' Predicate. It only accepts time.Time.

func (f TimeField) Desc() TimeField

Desc returns a new TimeField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.

func (f TimeField) Eq(field TimeField) Predicate

Eq returns an 'X = Y' Predicate. It only accepts TimeField.

EqTime returns an 'X = Y' Predicate. It only accepts time.Time.

func (f TimeField) Ge(field TimeField) Predicate

Ge returns an 'X >= Y' Predicate. It only accepts TimeField.

GeTime returns an 'X >= Y' Predicate. It only accepts time.Time.

GetAlias returns the alias of the TimeField.

GetName returns the name of the TimeField.

func (f TimeField) Gt(field TimeField) Predicate

Gt returns an 'X > Y' Predicate. It only accepts TimeField.

GtTime returns an 'X > Y' Predicate. It only accepts time.Time.

func (f TimeField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (f TimeField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (f TimeField) Le(field TimeField) Predicate

Le returns an 'X <= Y' Predicate. It only accepts TimeField.

LeTime returns an 'X <= Y' Predicate. It only accepts time.Time.

func (f TimeField) Lt(field TimeField) Predicate

Lt returns an 'X < Y' Predicate. It only accepts TimeField.

LtTime returns an 'X < Y' Predicate. It only accepts time.Time.

func (f TimeField) Ne(field TimeField) Predicate

Ne returns an 'X <> Y' Predicate. It only accepts TimeField.

NeTime returns an 'X <> Y' Predicate. It only accepts time.Time.

func (f TimeField) NotBetween(start, end TimeField) Predicate

NotBetween returns an 'X NOT BETWEEN Y AND Z' Predicate. It only accepts TimeField.

NotBetweenTime returns an 'X NOT BETWEEN Y AND Z' Predicate. It only accepts time.Time.

func (f TimeField) Set(value interface{}) FieldAssignment

Set returns a FieldAssignment associating the TimeField to the value i.e. 'field = value'.

SetTime returns a FieldAssignment associating the TimeField to the time.Time value i.e. 'field = value'.

String returns the string representation of the TimeField.

type UpdateQuery struct { Alias string

CTEs [][CTE](#CTE)

UpdateTable [BaseTable](#BaseTable)

Assignments [Assignments](#Assignments)

JoinTables [JoinTables](#JoinTables)

WherePredicate [VariadicPredicate](#VariadicPredicate)

OrderByFields [Fields](#Fields)

LimitValue *[int64](/builtin#int64)

DB           [DB](#DB)
ColumnMapper func(*[Column](#Column))

Log     [Logger](#Logger)
LogFlag [LogFlag](#LogFlag)

}

UpdateQuery represents an UPDATE query.

func Update(table BaseTable) UpdateQuery

Update creates a new UpdateQuery.

AppendSQL marshals the UpdateQuery into a buffer and args slice. Do not call this as an end user, use ToSQL instead. AppendSQL may panic if you wrote panic code in your ColumnMapper, it is only exported to satisfy the Query interface.

As aliases the UpdateQuery i.e. 'query AS alias'.

func (q UpdateQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) UpdateQuery

CustomJoin custom joins a table to the UpdateQuery. The join type can be specified with a string, e.g. "CROSS JOIN".

Exec will execute the UpdateQuery with the given DB. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.

ExecContext will execute the UpdateQuery with the given DB and context. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.

func (q UpdateQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery

FullJoin full joins a table to the UpdateQuery based on the predicates.

func (q UpdateQuery) Join(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery

Join joins a new table to the UpdateQuery based on the predicates.

func (q UpdateQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery

LeftJoin left joins a new table to the UpdateQuery based on the predicates.

func (q UpdateQuery) Limit(limit int) UpdateQuery

Limit sets the limit in the UpdateQuery.

func (q UpdateQuery) NestThis() Query

NestThis indicates to the UpdateQuery that it is nested.

func (q UpdateQuery) OrderBy(fields ...Field) UpdateQuery

OrderBy appends the fields to the ORDER BY clause in the UpdateQuery.

func (q UpdateQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery

RightJoin right joins a new table to the UpdateQuery based on the predicates.

func (q UpdateQuery) Set(assignments ...Assignment) UpdateQuery

Set appends the assignments to SET clause of the UpdateQuery.

func (q UpdateQuery) Setx(mapper func(*Column)) UpdateQuery

Setx sets the column mapper function UpdateQuery.

func (q UpdateQuery) ToSQL() (query string, args []interface{})

ToSQL marshals the UpdateQuery into a query string and args slice.

func (q UpdateQuery) Update(table BaseTable) UpdateQuery

Update sets the update table for the UpdateQuery.

func (q UpdateQuery) Where(predicates ...Predicate) UpdateQuery

Where appends the predicates to the WHERE clause in the UpdateQuery.

func (q UpdateQuery) With(ctes ...CTE) UpdateQuery

With appends a list of CTEs into the UpdateQuery.

type VariadicPredicate struct { Alias string Operator VariadicPredicateOperator Predicates []Predicate Negative bool

}

VariadicPredicate represents the "x AND y AND z..." or "x OR y OR z..." SQL construct.

func And

func And(predicates ...Predicate) VariadicPredicate

And joins the list of predicates together with the AND operator.

func Or(predicates ...Predicate) VariadicPredicate

Or joins the list of predicates together with the OR operator.

AppendSQLExclude marshals the VariadicPredicate into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.

GetAlias returns the alias of the VariadicPredicate.

GetName returns the name of the VariadicPredicate, which is always an empty string.

func (p VariadicPredicate) Not() Predicate

Not inverts the VariadicPredicate i.e. 'NOT VariadicPredicate'.

type VariadicPredicateOperator string

VariadicPredicateOperator is an operator that can join a variadic number of Predicates together.

const ( PredicateOr VariadicPredicateOperator = "OR" PredicateAnd VariadicPredicateOperator = "AND" )

VariadicPredicateOperators

type VariadicQuery struct { Operator VariadicQueryOperator Queries []Query

DB          [DB](#DB)
Mapper      func(*[Row](#Row))
Accumulator func()

Log     [Logger](#Logger)
LogFlag [LogFlag](#LogFlag)

}

VariadicQuery represents a variadic number of queries joined together by an VariadicQueryOperator.

func Except(queries ...Query) VariadicQuery

Except joins the list of queries together with the EXCEPT operator.

func ExceptAll(queries ...Query) VariadicQuery

ExceptAll joins the list of queries together with the EXCEPT ALL operator.

func Intersect(queries ...Query) VariadicQuery

Intersect joins the list of queries together with the INTERSECT operator.

func IntersectAll(queries ...Query) VariadicQuery

IntersectAll joins the list of queries together with the INTERSECT ALL operator.

func Union(queries ...Query) VariadicQuery

Union joins the list of queries together with the UNION operator.

func UnionAll(queries ...Query) VariadicQuery

UnionAll joins the list of queries together with the UNION ALL operator.

AppendSQL marshals the VariadicQuery into a buffer and args slice.

CTE converts a VariadicQuery into a CTE.

func (vq VariadicQuery) NestThis() Query

NestThis indicates to the VariadicQuery that it is nested.

Subquery converts a VariadicQuery into a Subquery.

func (vq VariadicQuery) ToSQL() (string, []interface{})

ToSQL marshals the VariadicQuery into a query string and args slice.

type VariadicQueryOperator string

VariadicQueryOperator is an operator that can join a variadic number of queries together.

const ( QueryUnion VariadicQueryOperator = "UNION" QueryUnionAll VariadicQueryOperator = "UNION ALL" QueryIntersect VariadicQueryOperator = "INTERSECT" QueryIntersectAll VariadicQueryOperator = "INTERSECT ALL" QueryExcept VariadicQueryOperator = "EXCEPT" QueryExceptAll VariadicQueryOperator = "EXCEPT ALL" )

VariadicQueryOperators

type Window struct { WindowName string

PartitionByFields [Fields](#Fields)
OrderByFields     [Fields](#Fields)
FrameDefinition   [string](/builtin#string)

}

Window represents a window usable in a window function.

func OrderBy(fields ...Field) Window

OrderBy creates a new Window.

func PartitionBy(fields ...Field) Window

PartitionBy creates a new Window.

AppendSQL marshals the Window into a buffer and args slice.

As aliases the VariadicQuery i.e. 'query AS alias'.

func (w Window) Frame(frameDefinition string) Window

Frame sets the frame definition of the window e.g. RANGE BETWEEN 5 PRECEDING AND 10 FOLLOWING.

func (w Window) Name() Window

Name returns the name of the Window.

func (w Window) OrderBy(fields ...Field) Window

OrderBy sets the fields of the window's ORDER BY clause.

func (w Window) PartitionBy(fields ...Field) Window

PartitionBy sets the fields of the window's PARTITION BY clause.

Windows is a list of Windows.

AppendSQL marshals the Windows into a buffer and args slice.