sq

package
Version: v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assignment

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

type Assignments []Assignment

Assignments is a list of Assignments.

func (Assignments) AppendSQLExclude

func (assignments Assignments) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

type BaseQuery

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

func With(CTEs ...CTE) BaseQuery

With creates a new BaseQuery with the CTEs.

func WithDB

func WithDB(db DB) BaseQuery

WithDB creates a new BaseQuery with the DB.

func WithDefaultLog

func WithDefaultLog(flag LogFlag) BaseQuery

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

func (BaseQuery) DeleteFrom

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

DeleteFrom transforms the BaseQuery into a DeleteQuery.

func (BaseQuery) From

func (q BaseQuery) From(table Table) SelectQuery

From transforms the BaseQuery into a SelectQuery.

func (BaseQuery) InsertIgnoreInto

func (q BaseQuery) InsertIgnoreInto(table BaseTable) InsertQuery

InsertIgnoreInto transforms the BaseQuery into an InsertQuery.

func (BaseQuery) InsertInto

func (q BaseQuery) InsertInto(table BaseTable) InsertQuery

InsertInto transforms the BaseQuery into an InsertQuery.

func (BaseQuery) Select

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

Select transforms the BaseQuery into a SelectQuery.

func (BaseQuery) SelectAll

func (q BaseQuery) SelectAll() SelectQuery

SelectAll transforms the BaseQuery into a SelectQuery.

func (BaseQuery) SelectCount

func (q BaseQuery) SelectCount() SelectQuery

SelectCount transforms the BaseQuery into a SelectQuery.

func (BaseQuery) SelectDistinct

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

SelectDistinct transforms the BaseQuery into a SelectQuery.

func (BaseQuery) SelectOne

func (q BaseQuery) SelectOne() SelectQuery

SelectOne transforms the BaseQuery into a SelectQuery.

func (BaseQuery) SelectRowx

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

SelectRowx transforms the BaseQuery into a SelectQuery.

func (BaseQuery) Selectx

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

Selectx transforms the BaseQuery into a SelectQuery.

func (BaseQuery) Union added in v0.2.0

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

Union transforms the BaseQuery into a VariadicQuery.

func (BaseQuery) UnionAll added in v0.2.0

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

UnionAll transforms the BaseQuery into a VariadicQuery.

func (BaseQuery) Update

func (q BaseQuery) Update(table BaseTable) UpdateQuery

Update transforms the BaseQuery into an UpdateQuery.

func (BaseQuery) With

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

With adds the CTEs to the BaseQuery

func (BaseQuery) WithDB

func (q BaseQuery) WithDB(db DB) BaseQuery

WithDB adds the DB to the BaseQuery.

func (BaseQuery) WithDefaultLog

func (q BaseQuery) WithDefaultLog(flag LogFlag) BaseQuery

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

type BaseTable

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

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

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

func Bytes

func Bytes(b []byte) BinaryField

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

func NewBinaryField

func NewBinaryField(name string, table Table) BinaryField

NewBinaryField returns a new BinaryField representing a BLOB column.

func (BinaryField) AppendSQLExclude

func (f BinaryField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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.

func (BinaryField) GetAlias

func (f BinaryField) GetAlias() string

GetAlias returns the alias of the BinaryField.

func (BinaryField) GetName

func (f BinaryField) GetName() string

GetName returns the name of the BinaryField.

func (BinaryField) IsNotNull

func (f BinaryField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (BinaryField) IsNull

func (f BinaryField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (BinaryField) Set

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

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

func (BinaryField) SetBytes

func (f BinaryField) SetBytes(b []byte) FieldAssignment

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

type BooleanField

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

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

func Bool

func Bool(b bool) BooleanField

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

func NewBooleanField

func NewBooleanField(name string, table Table) BooleanField

NewBooleanField returns a new BooleanField representing a boolean column.

func (BooleanField) AppendSQLExclude

func (f BooleanField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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.

func (BooleanField) As

func (f BooleanField) As(alias string) BooleanField

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

func (BooleanField) Asc

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 (BooleanField) Desc

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 (BooleanField) Eq

func (f BooleanField) Eq(field BooleanField) Predicate

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

func (BooleanField) GetAlias

func (f BooleanField) GetAlias() string

GetAlias returns the alias of the BooleanField.

func (BooleanField) GetName

func (f BooleanField) GetName() string

GetName returns the name of the BooleanField.

func (BooleanField) IsNotNull

func (f BooleanField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (BooleanField) IsNull

func (f BooleanField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (BooleanField) Ne

func (f BooleanField) Ne(field BooleanField) Predicate

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

func (BooleanField) Not

func (f BooleanField) Not() Predicate

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

func (BooleanField) Set

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

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

func (BooleanField) SetBool

func (f BooleanField) SetBool(val bool) FieldAssignment

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

func (BooleanField) String

func (f BooleanField) String() string

String returns the string representation of the BooleanField.

type CTE

type CTE map[string]CustomField

CTE represents an SQL CTE.

func RecursiveCTE added in v0.2.0

func RecursiveCTE(name string, columns ...string) CTE

RecursiveCTE constructs a new recursive CTE.

func (CTE) AppendSQL

func (cte CTE) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

AppendSQL marshals the CTE into a buffer and args slice.

func (CTE) As

func (cte CTE) As(alias string) CTE

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

func (CTE) GetAlias

func (cte CTE) GetAlias() string

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.

func (CTE) GetName

func (cte CTE) GetName() string

GetName returns the name of the CTE.

func (CTE) GetQuery added in v0.2.0

func (cte CTE) GetQuery() Query

GetQuery returns the CTE's underlying Query.

func (*CTE) Initial added in v0.2.0

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) IsRecursive added in v0.2.0

func (cte CTE) IsRecursive() bool

IsRecursive checks if the CTE is recursive.

type Column added in v0.4.0

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

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

func (col *Column) SetTime(field TimeField, value time.Time)

SetTime maps the time.Time value to the TimeField.

type CustomAssignment

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.

func (CustomAssignment) AppendSQLExclude

func (set CustomAssignment) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (CustomAssignment) AssertAssignment

func (set CustomAssignment) AssertAssignment()

AssertAssignment implements the Assignment interface.

type CustomField

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

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

Fieldf creates a new CustomField.

func FirstValueOver

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

FirstValueOver represents the FIRST_VALUE(field) OVER window function.

func LagOver

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

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

func LastValueOver

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

LastValueOver represents the LAST_VALUE(field) OVER window function.

func LeadOver

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

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

func NthValueOver

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

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

func Values

func Values(field Field) CustomField

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

func (CustomField) AppendSQLExclude

func (f CustomField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (CustomField) As

func (f CustomField) As(alias string) CustomField

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

func (CustomField) Asc

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 (CustomField) Desc

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 (CustomField) Eq

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

Eq returns an 'X = Y' Predicate.

func (CustomField) Ge

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

Ge returns an 'X >= Y' Predicate.

func (CustomField) GetAlias

func (f CustomField) GetAlias() string

GetAlias returns the alias of the CustomField.

func (CustomField) GetName

func (f CustomField) GetName() string

GetName returns the name of the CustomField.

func (CustomField) Gt

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

Gt returns an 'X > Y' Predicate.

func (CustomField) In

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

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

func (CustomField) IsNotNull

func (f CustomField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (CustomField) IsNull

func (f CustomField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (CustomField) Le

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

Le returns an 'X <= Y' Predicate.

func (CustomField) Lt

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

Lt returns an 'X < Y' Predicate.

func (CustomField) Ne

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

Ne returns an 'X <> Y' Predicate.

func (CustomField) String

func (f CustomField) String() string

String returns the string representation of the CustomField.

type CustomPredicate

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

func Exists(query Query) CustomPredicate

Exists represents the EXISTS() predicate.

func Predicatef

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

Predicatef creates a new CustomPredicate.

func (CustomPredicate) AppendSQLExclude

func (p CustomPredicate) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (CustomPredicate) As

As aliases the CustomPredicate.

func (CustomPredicate) GetAlias

func (p CustomPredicate) GetAlias() string

GetAlias returns the alias of the CustomPredicate.

func (CustomPredicate) GetName

func (p CustomPredicate) GetName() string

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

func (CustomPredicate) Not

func (p CustomPredicate) Not() Predicate

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

type DB

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

type DeleteQuery struct {
	Alias string
	// WITH
	CTEs []CTE
	// DELETE FROM
	FromTables []BaseTable
	// USING
	UsingTable Table
	JoinTables JoinTables
	// WHERE
	WherePredicate VariadicPredicate
	// ORDER BY
	OrderByFields Fields
	// LIMIT
	LimitValue *int64
	// DB
	DB DB
	// Logging
	Log     Logger
	LogFlag LogFlag
	// contains filtered or unexported fields
}

DeleteQuery represents a DELETE query.

func DeleteFrom

func DeleteFrom(tables ...BaseTable) DeleteQuery

DeleteFrom creates a new DeleteQuery.

func (DeleteQuery) AppendSQL

func (q DeleteQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

AppendSQL marshals the DeleteQuery into a buffer and args slice.

func (DeleteQuery) CustomJoin

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 (DeleteQuery) DeleteFrom

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

DeleteFrom adds new tables to delete from to the DeleteQuery.

func (DeleteQuery) Exec

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

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

func (DeleteQuery) ExecContext

func (q DeleteQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (rowsAffected int64, err error)

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 (DeleteQuery) FullJoin

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

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

func (DeleteQuery) Join

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

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

func (DeleteQuery) LeftJoin

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 (DeleteQuery) Limit

func (q DeleteQuery) Limit(limit int) DeleteQuery

Limit sets the limit in the DeleteQuery.

func (DeleteQuery) NestThis

func (q DeleteQuery) NestThis() Query

NestThis indicates to the DeleteQuery that it is nested.

func (DeleteQuery) OrderBy

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

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

func (DeleteQuery) RightJoin

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 (DeleteQuery) ToSQL

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

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

func (DeleteQuery) Using

func (q DeleteQuery) Using(table Table) DeleteQuery

Using adds a new table to the DeleteQuery.

func (DeleteQuery) Where

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

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

func (DeleteQuery) With

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

With appends the CTEs into the DeleteQuery.

type EnumField

type EnumField = StringField

EnumField is a type alias for StringField.

func NewEnumField

func NewEnumField(name string, table Table) EnumField

NewEnumField returns an EnumField representing an enum column.

type ExecFlag

type ExecFlag int

ExecFlag is a flag that affects the behavior of Exec.

const (
	ElastInsertID ExecFlag = 1 << iota
	ErowsAffected
)

ExecFlags

type ExitCode

type ExitCode int

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

const (
	ExitPeacefully ExitCode = iota
)

ExitCodes

func (ExitCode) Error

func (e ExitCode) Error() string

Error implements the error interface.

type Field

type Field interface {
	// Fields should respect the excludedTableQualifiers argument in ToSQL().
	// E.g. if the field 'name' belongs to a table called 'users' and the
	// excludedTableQualifiers contains 'users', the field should present itself
	// as 'name' and not 'users.name'. i.e. any table qualifiers in the list
	// must be excluded.
	//
	// This is to play nice with certain clauses in the INSERT and UPDATE
	// queries that expressly forbid table qualified columns.
	AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
	GetAlias() string
	GetName() string
}

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

type FieldAssignment

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'.

func (FieldAssignment) AppendSQLExclude

func (set FieldAssignment) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (FieldAssignment) AssertAssignment

func (set FieldAssignment) AssertAssignment()

AssertAssignment implements the Assignment interface.

type FieldLiteral

type FieldLiteral string

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

func (FieldLiteral) AppendSQLExclude

func (f FieldLiteral) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (FieldLiteral) GetAlias

func (f FieldLiteral) GetAlias() string

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

func (FieldLiteral) GetName

func (f FieldLiteral) GetName() string

GetName returns the FieldLiteral's underlying string.

type Fields

type Fields []Field

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

func (Fields) AppendSQLExclude

func (fs Fields) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (Fields) AppendSQLExcludeWithAlias

func (fs Fields) AppendSQLExcludeWithAlias(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

type InsertQuery struct {
	Alias string
	// INSERT INTO
	Ignore        bool
	IntoTable     BaseTable
	InsertColumns Fields
	// VALUES
	RowValues RowValues
	// SELECT
	SelectQuery *SelectQuery
	// ON DUPLICATE KEY
	Resolution Assignments
	// DB
	DB           DB
	ColumnMapper func(*Column)
	// Logging
	Log     Logger
	LogFlag LogFlag
	// contains filtered or unexported fields
}

InsertQuery represents an INSERT query.

func InsertIgnoreInto

func InsertIgnoreInto(table BaseTable) InsertQuery

InsertIgnoreInto creates a new InsertQuery.

func InsertInto

func InsertInto(table BaseTable) InsertQuery

InsertInto creates a new InsertQuery.

func (InsertQuery) AppendSQL

func (q InsertQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

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 (InsertQuery) Exec

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.

func (InsertQuery) ExecContext

func (q InsertQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (lastInsertID, rowsAffected int64, err error)

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 (InsertQuery) InsertIgnoreInto

func (q InsertQuery) InsertIgnoreInto(table BaseTable) InsertQuery

InsertIgnoreInto sets the insert table for the InsertQuery.

func (InsertQuery) InsertInto

func (q InsertQuery) InsertInto(table BaseTable) InsertQuery

InsertInto sets the insert table for the InsertQuery.

func (InsertQuery) NestThis

func (q InsertQuery) NestThis() Query

NestThis indicates to the InsertQuery that it is nested.

func (InsertQuery) OnDuplicateKeyUpdate

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

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

func (InsertQuery) Select

func (q InsertQuery) Select(selectQuery SelectQuery) InsertQuery

Select adds a SelectQuery to the InsertQuery.

func (InsertQuery) ToSQL

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

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

func (InsertQuery) Values

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

Values appends a new RowValue to the InsertQuery.

func (InsertQuery) Valuesx added in v0.4.0

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

Valuesx sets the column mapper for the InsertQuery.

type IntermediateCTE added in v0.2.3

type IntermediateCTE map[string]CustomField

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 (IntermediateCTE) Union added in v0.2.3

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 (IntermediateCTE) UnionAll added in v0.2.3

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

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

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

func JSON

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.

func JSONValue

func JSONValue(val driver.Valuer) JSONField

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

func MustJSON

func MustJSON(val interface{}) JSONField

MustJSON is like JSON but it panics on error.

func NewJSONField

func NewJSONField(name string, table Table) JSONField

NewJSONField returns a new JSONField representing a JSON column.

func (JSONField) AppendSQLExclude

func (f JSONField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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.

func (JSONField) As

func (f JSONField) As(alias string) JSONField

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

func (JSONField) Asc

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 (JSONField) Desc

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'.

func (JSONField) GetAlias

func (f JSONField) GetAlias() string

GetAlias returns the Alias of the JSONField.

func (JSONField) GetName

func (f JSONField) GetName() string

GetName returns the Name of the JSONField.

func (JSONField) IsNotNull

func (f JSONField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (JSONField) IsNull

func (f JSONField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (JSONField) Set

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

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

func (JSONField) SetJSON

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.

func (JSONField) SetValue

func (f JSONField) SetValue(value driver.Valuer) FieldAssignment

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

func (JSONField) String

func (f JSONField) String() string

String returns the string representation of the JSONField.

type JoinTable

type JoinTable struct {
	JoinType     JoinType
	Table        Table
	OnPredicates VariadicPredicate
}

JoinTable represents an SQL join.

func CustomJoin

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

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

FullJoin creates a new full join.

func Join

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

Join creates a new inner join.

func LeftJoin

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

LeftJoin creates a new left join.

func RightJoin

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

RightJoin creates a new right join.

func (JoinTable) AppendSQL

func (join JoinTable) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

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

type JoinTables

type JoinTables []JoinTable

JoinTables is a list of JoinTables.

func (JoinTables) AppendSQL

func (joins JoinTables) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

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

type JoinType

type JoinType string

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

type LogFlag

type LogFlag int

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

const (
	Linterpolate LogFlag = 1 << iota
	Lstats
	Lresults
	// Lparse
	Lverbose = Lstats | Lresults
)

LogFlags

type Logger

type Logger interface {
	Output(calldepth int, s string) error
}

Logger is an interface that provides logging.

type NumberField

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

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

func Avg

func Avg(field interface{}) NumberField

Avg represents the AVG() aggregate function.

func AvgOver

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

AvgOver represents the AVG() OVER window function.

func Count

func Count() NumberField

Count represents the COUNT(*) aggregate function.

func CountOver

func CountOver(window Window) NumberField

CountOver represents the COUNT(*) OVER window function.

func CumeDistOver

func CumeDistOver(window Window) NumberField

CumeDistOver represents the CUME_DIST() OVER window function.

func DenseRankOver

func DenseRankOver(window Window) NumberField

DenseRankOver represents the DENSE_RANK() OVER window function.

func Float64

func Float64(num float64) NumberField

Float64 returns a new NumberField representing a literal float64 value.

func Int

func Int(num int) NumberField

Int returns a new NumberField representing a literal int value.

func Int64

func Int64(num int64) NumberField

Int64 returns a new NumberField representing a literal int64 value.

func Max

func Max(field interface{}) NumberField

Max represents the MAX() aggregate function.

func MaxOver

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

MaxOver represents the MAX() OVER window function.

func Min

func Min(field interface{}) NumberField

Min represents the MIN() aggregate function.

func MinOver

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

MinOver represents the MIN() OVER window function.

func NewNumberField

func NewNumberField(name string, table Table) NumberField

NewNumberField returns a new NumberField representing a number TableInfo column.

func NtileOver

func NtileOver(n int, window Window) NumberField

NtileOver represents the NTILE(n) OVER window function.

func NumberFieldf

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

NumberFieldf creates a new number expression.

func PercentRankOver

func PercentRankOver(window Window) NumberField

PercentRankOver represents the PERCENT_RANK() OVER window function.

func RankOver

func RankOver(window Window) NumberField

RankOver represents the RANK() OVER window function.

func RowNumberOver

func RowNumberOver(window Window) NumberField

RowNumberOver represents the ROW_NUMBER() OVER window function.

func Sum

func Sum(field interface{}) NumberField

Sum represents the SUM() aggregate function.

func SumOver

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

SumOver represents the SUM() OVER window function.

func (NumberField) AppendSQLExclude

func (f NumberField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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.

func (NumberField) As

func (f NumberField) As(alias string) NumberField

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

func (NumberField) Asc

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 (NumberField) Desc

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 (NumberField) Eq

func (f NumberField) Eq(field NumberField) Predicate

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

func (NumberField) EqFloat64

func (f NumberField) EqFloat64(num float64) Predicate

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

func (NumberField) EqInt

func (f NumberField) EqInt(num int) Predicate

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

func (NumberField) Ge

func (f NumberField) Ge(field NumberField) Predicate

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

func (NumberField) GeFloat64

func (f NumberField) GeFloat64(num float64) Predicate

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

func (NumberField) GeInt

func (f NumberField) GeInt(num int) Predicate

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

func (NumberField) GetAlias

func (f NumberField) GetAlias() string

GetAlias returns the alias of the NumberField.

func (NumberField) GetName

func (f NumberField) GetName() string

GetName returns the name of the NumberField.

func (NumberField) Gt

func (f NumberField) Gt(field NumberField) Predicate

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

func (NumberField) GtFloat64

func (f NumberField) GtFloat64(num float64) Predicate

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

func (NumberField) GtInt

func (f NumberField) GtInt(num int) Predicate

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

func (NumberField) In

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

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

func (NumberField) IsNotNull

func (f NumberField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (NumberField) IsNull

func (f NumberField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (NumberField) Le

func (f NumberField) Le(field NumberField) Predicate

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

func (NumberField) LeFloat64

func (f NumberField) LeFloat64(num float64) Predicate

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

func (NumberField) LeInt

func (f NumberField) LeInt(num int) Predicate

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

func (NumberField) Lt

func (f NumberField) Lt(field NumberField) Predicate

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

func (NumberField) LtFloat64

func (f NumberField) LtFloat64(num float64) Predicate

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

func (NumberField) LtInt

func (f NumberField) LtInt(num int) Predicate

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

func (NumberField) Ne

func (f NumberField) Ne(field NumberField) Predicate

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

func (NumberField) NeFloat64

func (f NumberField) NeFloat64(num float64) Predicate

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

func (NumberField) NeInt

func (f NumberField) NeInt(num int) Predicate

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

func (NumberField) Set

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

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

func (NumberField) SetFloat64

func (f NumberField) SetFloat64(num float64) FieldAssignment

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

func (NumberField) SetInt

func (f NumberField) SetInt(num int) FieldAssignment

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

func (NumberField) SetInt64

func (f NumberField) SetInt64(num int64) FieldAssignment

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

func (NumberField) String

func (f NumberField) String() string

String returns the string representation of the NumberField.

type Predicate

type Predicate interface {
	Field
	Not() Predicate
}

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

func Eq added in v0.2.0

func Eq(f1, f2 interface{}) Predicate

Eq returns an 'X = Y' Predicate.

func Ge added in v0.2.0

func Ge(f1, f2 interface{}) Predicate

Ge returns an 'X >= Y' Predicate.

func Gt added in v0.2.0

func Gt(f1, f2 interface{}) Predicate

Gt returns an 'X > Y' Predicate.

func Le added in v0.2.0

func Le(f1, f2 interface{}) Predicate

Le returns an 'X <= Y' Predicate.

func Lt added in v0.2.0

func Lt(f1, f2 interface{}) Predicate

Lt returns an 'X < Y' Predicate.

func Ne added in v0.2.0

func Ne(f1, f2 interface{}) Predicate

Ne returns an 'X <> Y' Predicate.

func Not

func Not(predicate Predicate) Predicate

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

type PredicateCase

type PredicateCase struct {
	Condition Predicate
	Result    interface{}
}

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

type PredicateCases

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

PredicateCases is the general form of the CASE expression.

func CaseWhen

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

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

func (PredicateCases) AppendSQLExclude

func (f PredicateCases) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (PredicateCases) As

func (f PredicateCases) As(alias string) PredicateCases

As aliases the PredicateCases.

func (PredicateCases) Else

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

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

func (PredicateCases) GetAlias

func (f PredicateCases) GetAlias() string

GetAlias returns the alias of the PredicateCases.

func (PredicateCases) GetName

func (f PredicateCases) GetName() string

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

func (PredicateCases) When

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

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

type Query

type Query interface {
	AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
	// When NestThis is called on a query, it signals to the query that it is
	// being nested as part of a larger query. The nested query should:
	// - hold off logging anything because the parent query will do it
	NestThis() Query
	ToSQL() (string, []interface{})
}

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

type Row

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

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

func (*Row) Bool

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 (*Row) BoolValid

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.

func (*Row) Float64

func (r *Row) Float64(field NumberField) float64

Float64 returns the float64 value of the NumberField.

func (*Row) Float64Valid

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

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

func (*Row) Int

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

Int returns the int value of the NumberField.

func (*Row) Int64

func (r *Row) Int64(field NumberField) int64

Int64 returns the int64 value of the NumberField.

func (*Row) Int64Valid

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

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

func (*Row) IntValid

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

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

func (*Row) NullBool

func (r *Row) NullBool(predicate Predicate) sql.NullBool

NullBool returns the sql.NullBool value of the Predicate.

func (*Row) NullFloat64

func (r *Row) NullFloat64(field NumberField) sql.NullFloat64

NullFloat64 returns the sql.NullFloat64 value of the NumberField.

func (*Row) NullInt64

func (r *Row) NullInt64(field NumberField) sql.NullInt64

NullInt64 returns the sql.NullInt64 value of the NumberField.

func (*Row) NullString

func (r *Row) NullString(field StringField) sql.NullString

NullString returns the sql.NullString value of the StringField.

func (*Row) NullTime

func (r *Row) NullTime(field TimeField) sql.NullTime

NullTime returns the sql.NullTime value of the TimeField.

func (*Row) ScanInto

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

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

func (*Row) String

func (r *Row) String(field StringField) string

String returns the string value of the StringField.

func (*Row) StringValid

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

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

func (*Row) Time

func (r *Row) Time(field TimeField) time.Time

Time returns the time.Time value of the TimeField.

func (*Row) TimeValid

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

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

type RowValue

type RowValue []interface{}

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

func (RowValue) AppendSQL

func (r RowValue) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

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

func (RowValue) AppendSQLExclude

func (r RowValue) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (RowValue) In

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

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

func (RowValue) Set

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

Set returns an Assignment assigning v to the RowValue.

type RowValues

type RowValues []RowValue

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

func (RowValues) AppendSQL

func (rs RowValues) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

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

type SelectQuery

type SelectQuery struct {
	Alias string
	// WITH
	CTEs []CTE
	// SELECT
	SelectType   SelectType
	SelectFields Fields
	// FROM
	FromTable  Table
	JoinTables JoinTables
	// WHERE
	WherePredicate VariadicPredicate
	// GROUP BY
	GroupByFields Fields
	// HAVING
	HavingPredicate VariadicPredicate
	// WINDOW
	Windows Windows
	// ORDER BY
	OrderByFields Fields
	// LIMIT
	LimitValue *int64
	// OFFSET
	OffsetValue *int64
	// DB
	DB          DB
	RowMapper   func(*Row)
	Accumulator func()
	// Logging
	Log     Logger
	LogFlag LogFlag
	// contains filtered or unexported fields
}

SelectQuery represents a SELECT query.

func From

func From(table Table) SelectQuery

From creates a new SelectQuery.

func Select

func Select(fields ...Field) SelectQuery

Select creates a new SelectQuery.

func SelectDistinct

func SelectDistinct(fields ...Field) SelectQuery

SelectDistinct creates a new SelectQuery.

func SelectOne

func SelectOne() SelectQuery

SelectOne creates a new SelectQuery.

func SelectRowx

func SelectRowx(mapper func(*Row)) SelectQuery

SelectRowx creates a new SelectQuery.

func Selectx

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

Selectx creates a new SelectQuery.

func (SelectQuery) AppendSQL

func (q SelectQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

AppendSQL marshals the SelectQuery into a buffer and args slice.

func (SelectQuery) CTE added in v0.2.0

func (q SelectQuery) CTE(name string, columns ...string) CTE

CTE converts a SelectQuery into a CTE.

func (SelectQuery) CustomJoin

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 (SelectQuery) Fetch

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).

func (SelectQuery) FetchContext

func (q SelectQuery) FetchContext(ctx context.Context, db DB) (err error)

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 (SelectQuery) From

func (q SelectQuery) From(table Table) SelectQuery

From sets the table in the SelectQuery.

func (SelectQuery) FullJoin

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

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

func (SelectQuery) GroupBy

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

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

func (SelectQuery) Having

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

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

func (SelectQuery) Join

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

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

func (SelectQuery) LeftJoin

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 (SelectQuery) Limit

func (q SelectQuery) Limit(limit int) SelectQuery

Limit sets the limit in the SelectQuery.

func (SelectQuery) NestThis

func (q SelectQuery) NestThis() Query

NestThis indicates to the SelectQuery that it is nested.

func (SelectQuery) Offset

func (q SelectQuery) Offset(offset int) SelectQuery

Offset sets the offset in the SelectQuery.

func (SelectQuery) OrderBy

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

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

func (SelectQuery) RightJoin

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 (SelectQuery) Select

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

Select adds the fields to the SelectFields in the SelectQuery.

func (SelectQuery) SelectAll

func (q SelectQuery) SelectAll() SelectQuery

SelectAll sets the SELECT clause to SELECT *.

func (SelectQuery) SelectCount

func (q SelectQuery) SelectCount() SelectQuery

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

func (SelectQuery) SelectDistinct

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

SelectDistinct adds the fields to the SelectFields in the SelectQuery.

func (SelectQuery) SelectOne

func (q SelectQuery) SelectOne() SelectQuery

SelectOne sets the SELECT clause to SELECT 1.

func (SelectQuery) SelectRowx

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

SelectRowx sets the mapper function in the SelectQuery.

func (SelectQuery) Selectx

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

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

func (SelectQuery) Subquery added in v0.2.0

func (q SelectQuery) Subquery(alias string) Subquery

Subquery converts a SelectQuery into a Subquery.

func (SelectQuery) ToSQL

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

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

func (SelectQuery) Where

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

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

func (SelectQuery) Window

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

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

func (SelectQuery) With

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

With appends a list of CTEs into the SelectQuery.

type SelectType

type SelectType string

SelectType represents the various SQL selects.

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

SelectTypes

type SimpleCase

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

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

type SimpleCases

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

SimpleCases is the simple form of the CASE expression.

func Case

func Case(field Field) SimpleCases

Case creates a new SimpleCases i.e. CASE X

func (SimpleCases) AppendSQLExclude

func (f SimpleCases) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (SimpleCases) As

func (f SimpleCases) As(alias string) SimpleCases

As aliases the SimpleCases.

func (SimpleCases) Else

func (f SimpleCases) Else(field Field) SimpleCases

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

func (SimpleCases) GetAlias

func (f SimpleCases) GetAlias() string

GetAlias returns the alias of the SimpleCases.

func (SimpleCases) GetName

func (f SimpleCases) GetName() string

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

func (SimpleCases) When

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

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

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

func NewStringField

func NewStringField(name string, table Table) StringField

NewStringField returns a new StringField representing a boolean column.

func String

func String(s string) StringField

String returns a new StringField representing a literal string value.

func (StringField) AppendSQLExclude

func (f StringField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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.

func (StringField) As

func (f StringField) As(alias string) StringField

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

func (StringField) Asc

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 (StringField) Desc

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 (StringField) Eq

func (f StringField) Eq(field StringField) Predicate

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

func (StringField) EqString

func (f StringField) EqString(s string) Predicate

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

func (StringField) Ge

func (f StringField) Ge(field StringField) Predicate

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

func (StringField) GeString

func (f StringField) GeString(s string) Predicate

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

func (StringField) GetAlias

func (f StringField) GetAlias() string

GetAlias returns the alias of the StringField.

func (StringField) GetName

func (f StringField) GetName() string

GetName returns the name of the StringField.

func (StringField) Gt

func (f StringField) Gt(field StringField) Predicate

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

func (StringField) GtString

func (f StringField) GtString(s string) Predicate

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

func (StringField) In

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

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

func (StringField) IsNotNull

func (f StringField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (StringField) IsNull

func (f StringField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (StringField) Le

func (f StringField) Le(field StringField) Predicate

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

func (StringField) LeString

func (f StringField) LeString(s string) Predicate

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

func (StringField) LikeString

func (f StringField) LikeString(s string) Predicate

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

func (StringField) Lt

func (f StringField) Lt(field StringField) Predicate

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

func (StringField) LtString

func (f StringField) LtString(s string) Predicate

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

func (StringField) Ne

func (f StringField) Ne(field StringField) Predicate

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

func (StringField) NeString

func (f StringField) NeString(s string) Predicate

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

func (StringField) NotLikeString

func (f StringField) NotLikeString(s string) Predicate

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

func (StringField) Set

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

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

func (StringField) SetString

func (f StringField) SetString(s string) FieldAssignment

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

func (StringField) String

func (f StringField) String() string

String returns the string representation of the StringField.

type Subquery added in v0.2.0

type Subquery map[string]CustomField

Subquery represents an SQL subquery.

func (Subquery) AppendSQL added in v0.2.0

func (subq Subquery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

AppendSQL marshals the Subquery into a buffer and args slice.

func (Subquery) GetAlias added in v0.2.0

func (subq Subquery) GetAlias() string

GetAlias returns the alias of the Subquery.

func (Subquery) GetName added in v0.2.0

func (subq Subquery) GetName() string

GetName returns the name of the Subquery.

func (Subquery) GetQuery added in v0.2.0

func (subq Subquery) GetQuery() Query

GetQuery returns the Subquery's underlying Query.

func (Subquery) NestThis added in v0.2.0

func (subq Subquery) NestThis() Query

NestThis indicates to the Subquery that it is nested.

func (Subquery) ToSQL added in v0.2.0

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

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

type Table

type Table interface {
	AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
	GetAlias() string
	GetName() string
}

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

type TableInfo

type TableInfo struct {
	Schema string
	Name   string
	Alias  string
}

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.

func (*TableInfo) AppendSQL

func (tbl *TableInfo) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

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

func (*TableInfo) AssertBaseTable

func (tbl *TableInfo) AssertBaseTable()

AssertBaseTable implements the BaseTable interface.

func (*TableInfo) GetAlias

func (tbl *TableInfo) GetAlias() string

GetAlias returns the alias of the TableInfo.

func (*TableInfo) GetName

func (tbl *TableInfo) GetName() string

GetName returns the name of the TableInfo.

type TimeField

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

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

func NewTimeField

func NewTimeField(name string, table Table) TimeField

NewTimeField returns a new TimeField representing a time column.

func Time

func Time(t time.Time) TimeField

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

func (TimeField) AppendSQLExclude

func (f TimeField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (TimeField) As

func (f TimeField) As(alias string) TimeField

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

func (TimeField) Asc

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 (TimeField) Between

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

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

func (TimeField) BetweenTime

func (f TimeField) BetweenTime(start, end time.Time) Predicate

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

func (TimeField) Desc

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 (TimeField) Eq

func (f TimeField) Eq(field TimeField) Predicate

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

func (TimeField) EqTime

func (f TimeField) EqTime(t time.Time) Predicate

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

func (TimeField) Ge

func (f TimeField) Ge(field TimeField) Predicate

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

func (TimeField) GeTime

func (f TimeField) GeTime(t time.Time) Predicate

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

func (TimeField) GetAlias

func (f TimeField) GetAlias() string

GetAlias returns the alias of the TimeField.

func (TimeField) GetName

func (f TimeField) GetName() string

GetName returns the name of the TimeField.

func (TimeField) Gt

func (f TimeField) Gt(field TimeField) Predicate

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

func (TimeField) GtTime

func (f TimeField) GtTime(t time.Time) Predicate

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

func (TimeField) IsNotNull

func (f TimeField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (TimeField) IsNull

func (f TimeField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (TimeField) Le

func (f TimeField) Le(field TimeField) Predicate

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

func (TimeField) LeTime

func (f TimeField) LeTime(t time.Time) Predicate

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

func (TimeField) Lt

func (f TimeField) Lt(field TimeField) Predicate

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

func (TimeField) LtTime

func (f TimeField) LtTime(t time.Time) Predicate

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

func (TimeField) Ne

func (f TimeField) Ne(field TimeField) Predicate

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

func (TimeField) NeTime

func (f TimeField) NeTime(t time.Time) Predicate

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

func (TimeField) NotBetween

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

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

func (TimeField) NotBetweenTime

func (f TimeField) NotBetweenTime(start, end time.Time) Predicate

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

func (TimeField) Set

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

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

func (TimeField) SetTime

func (f TimeField) SetTime(value time.Time) FieldAssignment

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

func (TimeField) String

func (f TimeField) String() string

String returns the string representation of the TimeField.

type UpdateQuery

type UpdateQuery struct {
	Alias string
	// WITH
	CTEs []CTE
	// UPDATE
	UpdateTable BaseTable
	// SET
	Assignments Assignments
	// JOIN
	JoinTables JoinTables
	// WHERE
	WherePredicate VariadicPredicate
	// ORDER BY
	OrderByFields Fields
	// LIMIT
	LimitValue *int64
	// DB
	DB           DB
	ColumnMapper func(*Column)
	// Logging
	Log     Logger
	LogFlag LogFlag
	// contains filtered or unexported fields
}

UpdateQuery represents an UPDATE query.

func Update

func Update(table BaseTable) UpdateQuery

Update creates a new UpdateQuery.

func (UpdateQuery) AppendSQL

func (q UpdateQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

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.

func (UpdateQuery) As

func (q UpdateQuery) As(alias string) UpdateQuery

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

func (UpdateQuery) CustomJoin

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".

func (UpdateQuery) Exec

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

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

func (UpdateQuery) ExecContext

func (q UpdateQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (rowsAffected int64, err error)

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 (UpdateQuery) FullJoin

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

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

func (UpdateQuery) Join

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

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

func (UpdateQuery) LeftJoin

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 (UpdateQuery) Limit

func (q UpdateQuery) Limit(limit int) UpdateQuery

Limit sets the limit in the UpdateQuery.

func (UpdateQuery) NestThis

func (q UpdateQuery) NestThis() Query

NestThis indicates to the UpdateQuery that it is nested.

func (UpdateQuery) OrderBy

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

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

func (UpdateQuery) RightJoin

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 (UpdateQuery) Set

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

Set appends the assignments to SET clause of the UpdateQuery.

func (UpdateQuery) Setx added in v0.4.0

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

Setx sets the column mapper function UpdateQuery.

func (UpdateQuery) ToSQL

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

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

func (UpdateQuery) Update

func (q UpdateQuery) Update(table BaseTable) UpdateQuery

Update sets the update table for the UpdateQuery.

func (UpdateQuery) Where

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

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

func (UpdateQuery) With

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

With appends a list of CTEs into the UpdateQuery.

type VariadicPredicate

type VariadicPredicate struct {
	Alias      string
	Operator   VariadicPredicateOperator
	Predicates []Predicate
	Negative   bool
	// contains filtered or unexported fields
}

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

func Or(predicates ...Predicate) VariadicPredicate

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

func (VariadicPredicate) AppendSQLExclude

func (p VariadicPredicate) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)

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

func (VariadicPredicate) GetAlias

func (p VariadicPredicate) GetAlias() string

GetAlias returns the alias of the VariadicPredicate.

func (VariadicPredicate) GetName

func (p VariadicPredicate) GetName() string

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

func (VariadicPredicate) Not

func (p VariadicPredicate) Not() Predicate

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

type VariadicPredicateOperator

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

type VariadicQuery struct {
	Operator VariadicQueryOperator
	Queries  []Query
	// DB
	DB          DB
	Mapper      func(*Row)
	Accumulator func()
	// Logging
	Log     Logger
	LogFlag LogFlag
	// contains filtered or unexported fields
}

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

func Except

func Except(queries ...Query) VariadicQuery

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

func ExceptAll

func ExceptAll(queries ...Query) VariadicQuery

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

func Intersect

func Intersect(queries ...Query) VariadicQuery

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

func IntersectAll

func IntersectAll(queries ...Query) VariadicQuery

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

func Union

func Union(queries ...Query) VariadicQuery

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

func UnionAll

func UnionAll(queries ...Query) VariadicQuery

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

func (VariadicQuery) AppendSQL

func (vq VariadicQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

AppendSQL marshals the VariadicQuery into a buffer and args slice.

func (VariadicQuery) CTE added in v0.2.0

func (vq VariadicQuery) CTE(name string, columns ...string) CTE

CTE converts a VariadicQuery into a CTE.

func (VariadicQuery) NestThis

func (vq VariadicQuery) NestThis() Query

NestThis indicates to the VariadicQuery that it is nested.

func (VariadicQuery) Subquery added in v0.2.0

func (vq VariadicQuery) Subquery(name string) Subquery

Subquery converts a VariadicQuery into a Subquery.

func (VariadicQuery) ToSQL

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

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

type VariadicQueryOperator

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

type Window struct {
	WindowName string

	PartitionByFields Fields
	OrderByFields     Fields
	FrameDefinition   string
	// contains filtered or unexported fields
}

Window represents a window usable in a window function.

func OrderBy

func OrderBy(fields ...Field) Window

OrderBy creates a new Window.

func PartitionBy

func PartitionBy(fields ...Field) Window

PartitionBy creates a new Window.

func (Window) AppendSQL

func (w Window) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

AppendSQL marshals the Window into a buffer and args slice.

func (Window) As

func (w Window) As(name string) Window

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

func (Window) Frame

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 (Window) Name

func (w Window) Name() Window

Name returns the name of the Window.

func (Window) OrderBy

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

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

func (Window) PartitionBy

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

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

type Windows

type Windows []Window

Windows is a list of Windows.

func (Windows) AppendSQL

func (ws Windows) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)

AppendSQL marshals the Windows into a buffer and args slice.

Jump to

Keyboard shortcuts

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