sq

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSQLDisplay

func AppendSQLDisplay(buf *strings.Builder, value interface{})

AppendSQLDisplay marshals an interface value into a buffer.

func AppendSQLValue

func AppendSQLValue(buf Buffer, args *[]interface{}, excludedTableQualifiers []string, value interface{})

AppendSQLValue will write the SQL representation of the interface{} value into the buffer and args slice. It propagates excludedTableQualifiers where relevant.

func ExpandValues

func ExpandValues(buf Buffer, args *[]interface{}, excludedTableQualifiers []string, format string, values []interface{})

ExpandValues will expand each value one by one into successive question mark ? placeholders in the format string, writing the results into the buffer and args slice. It propagates the excludedTableQualifiers down to its child elements.

func InterpolateSQLValue

func InterpolateSQLValue(buf *strings.Builder, value interface{})

InterpolateSQLValue interpolates an interface value as its SQL representation into a buffer. This makes it vulnerable to SQL injection and should be used for display purposes ONLY, not for actually running against a database.

func QuestionInterpolate

func QuestionInterpolate(query string, args ...interface{}) string

QuestionInterpolate interpolates the question mark ? placeholders in a query string with the args in the args slice. It is vulnerable to SQL injection and should be used for display purposes only, not for actually running against a database.

func RandomString

func RandomString(n int) string

RandomString is the RandStringBytesMaskImprSrcSB function taken from https://stackoverflow.com/a/31832326. It generates a random alphabetical string of length n.

Types

type AliasedCTE

type AliasedCTE struct {
	Name  string
	Alias string
}

AliasedCTE is an aliased version of a CTE derived from a parent CTE.

func (AliasedCTE) AppendSQL

func (cte AliasedCTE) AppendSQL(buf Buffer, _ *[]interface{})

AppendSQL marshals the AliasedCTE name into a buffer and an args slice. There is no need for it to write the alias into the buffer, as the caller of AppendSQL should be responsible for checking for the alias as well.

func (AliasedCTE) Get

func (cte AliasedCTE) Get(fieldName string) CustomField

Get returns a Field from the AliasedCTE, identified by fieldName.

func (AliasedCTE) GetAlias

func (cte AliasedCTE) GetAlias() string

GetAlias returns the alias of the AliasedCTE.

func (AliasedCTE) GetName

func (cte AliasedCTE) GetName() string

GetAlias returns the name of the parent CTE.

type Assignment

type Assignment interface {
	AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)
	AssertAssignment()
}

Assignment is an interface representing an assignment used in the UPDATE or INSERT query.

type Assignments

type Assignments []Assignment

Assignments is a list of Assignments.

func (Assignments) AppendSQLExclude

func (assignments Assignments) AppendSQLExclude(buf Buffer, args *[]interface{}, 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    CTEs
}

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 WithLog

func WithLog(logger Logger, flag LogFlag) BaseQuery

WithLog creates a new BaseQuery with a custom 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) 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.

func (BaseQuery) WithLog

func (q BaseQuery) WithLog(logger Logger, flag LogFlag) BaseQuery

WithLog adds a custom 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 Buffer, args *[]interface{}, 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 Buffer, args *[]interface{}, 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 Buffer

type Buffer interface {
	io.StringWriter
	String() string
	Reset()
}

Buffer is an

type CTE

type CTE struct {
	Recursive bool
	Name      string
	Query     Query
	Columns   []string
}

CTE represents an SQL Common Table Expression.

func NewCTE

func NewCTE(name string, query Query, columns ...string) CTE

NewCTE creates a new CTE.

func NewRecursiveCTE

func NewRecursiveCTE(name string, query Query, columns ...string) CTE

NewRecursiveCTE creates a new recursive CTE.

func (CTE) AppendSQL

func (cte CTE) AppendSQL(buf Buffer, args *[]interface{})

AppendSQL marshals the CTE name into a buffer and an args slice.

func (CTE) As

func (cte CTE) As(alias string) AliasedCTE

As aliases the CTE and returns an AliasedCTE.

func (CTE) Get

func (cte CTE) Get(fieldName string) CustomField

Get returns a Field from the CTE, identified by fieldName.

func (CTE) GetAlias

func (cte CTE) GetAlias() string

GetAlias returns the alias of the CTE, which is always an empty string. This is because CTEs do not have aliases, only AliasedCTEs do.

func (CTE) GetName

func (cte CTE) GetName() string

GetName returns the name of the CTE.

type CTEs

type CTEs []CTE

CTEs represents a list of CTEs

func (CTEs) AppendSQL

func (ctes CTEs) AppendSQL(buf Buffer, args *[]interface{})

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

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 Buffer, args *[]interface{}, 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 Buffer, args *[]interface{}, 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

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 Buffer, args *[]interface{}, 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 CustomQuery

type CustomQuery struct {
	Nested bool
	Alias  string
	Format string
	Values []interface{}
}

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

func Queryf

func Queryf(format string, values ...interface{}) CustomQuery

Queryf creates a new CustomQuery.

func (CustomQuery) AppendSQL

func (q CustomQuery) AppendSQL(buf Buffer, args *[]interface{})

AppendSQL marshals CustomQuery into a buffer and an args slice.

func (CustomQuery) As

func (q CustomQuery) As(alias string) CustomQuery

As aliases the CustomQuery i.e. 'query AS Alias'.

func (CustomQuery) GetAlias

func (q CustomQuery) GetAlias() string

GetAlias returns the alias of the CustomQuery.

func (CustomQuery) GetName

func (q CustomQuery) GetName() string

GetName returns the name of the CustomQuery.

func (CustomQuery) NestThis

func (q CustomQuery) NestThis() Query

NestThis indicates to the Query that it is nested.

func (CustomQuery) ToSQL

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

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

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 {
	Nested bool
	Alias  string
	// WITH
	CTEs CTEs
	// 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
	LogSkip int
}

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 Buffer, args *[]interface{})

AppendSQL marshals the DeleteQuery into a buffer and args slice.

func (DeleteQuery) As

func (q DeleteQuery) As(alias string) DeleteQuery

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

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

func (q DeleteQuery) GetAlias() string

GetAlias returns the alias of the DeleteQuery.

func (DeleteQuery) GetName

func (q DeleteQuery) GetName() string

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

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 a list of 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 Buffer, args *[]interface{}, 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 Buffer, args *[]interface{}, 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 Buffer, _ *[]interface{}, _ []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 Buffer, args *[]interface{}, 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 Buffer, args *[]interface{}, 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 {
	Nested bool
	Alias  string
	// INSERT INTO
	Ignore        bool
	IntoTable     BaseTable
	InsertColumns Fields
	// VALUES
	RowValues RowValues
	// SELECT
	SelectQuery *SelectQuery
	// ON DUPLICATE KEY
	Resolution Assignments
	// DB
	DB DB
	// Logging
	Log     Logger
	LogFlag LogFlag
	LogSkip int
}

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 Buffer, args *[]interface{})

AppendSQL marshals the InsertQuery into a buffer and args slice.

func (InsertQuery) As

func (q InsertQuery) As(alias string) InsertQuery

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

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

func (q InsertQuery) GetAlias() string

GetAlias returns the alias of the InsertQuery.

func (InsertQuery) GetName

func (q InsertQuery) GetName() string

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

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

func (q InsertQuery) InsertRow(assignments ...FieldAssignment) InsertQuery

InsertRow appends a new RowValue to the InsertQuery. It also sets the insert columns if not already set.

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() (string, []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.

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 Buffer, args *[]interface{}, 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 Buffer, args *[]interface{})

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 Buffer, args *[]interface{})

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 Buffer, args *[]interface{}, 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 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 Buffer, args *[]interface{}, 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 {
	Table
	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 Buffer, args *[]interface{})

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

func (RowValue) AppendSQLExclude

func (r RowValue) AppendSQLExclude(buf Buffer, args *[]interface{}, 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 Buffer, args *[]interface{})

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

type SelectQuery

type SelectQuery struct {
	Nested bool
	Alias  string
	// WITH
	CTEs CTEs
	// 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
	Mapper      func(*Row)
	Accumulator func()
	// Logging
	Log     Logger
	LogFlag LogFlag
	LogSkip int
}

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 Buffer, args *[]interface{})

AppendSQL marshals the SelectQuery into a buffer and args slice.

func (SelectQuery) As

func (q SelectQuery) As(alias string) SelectQuery

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

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

func (q SelectQuery) Get(fieldName string) CustomField

Get returns a Field from the SelectQuery, identified by fieldName.

func (SelectQuery) GetAlias

func (q SelectQuery) GetAlias() string

GetAlias returns the alias of the SelectQuery.

func (SelectQuery) GetName

func (q SelectQuery) GetName() string

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

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) 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 Buffer, args *[]interface{}, 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 Buffer, args *[]interface{}, 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 Table

type Table interface {
	AppendSQL(buf Buffer, args *[]interface{})
	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 Buffer, args *[]interface{})

AppendSQLExclude 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 Buffer, args *[]interface{}, 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 {
	Nested bool
	Alias  string
	// WITH
	CTEs CTEs
	// UPDATE
	UpdateTable BaseTable
	// SET
	Assignments Assignments
	// JOIN
	JoinTables JoinTables
	// WHERE
	WherePredicate VariadicPredicate
	// ORDER BY
	OrderByFields Fields
	// LIMIT
	LimitValue *int64
	// DB
	DB DB
	// Logging
	Log     Logger
	LogFlag LogFlag
	LogSkip int
}

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 Buffer, args *[]interface{})

AppendSQL marshals the UpdateQuery into a buffer and args slice.

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

func (q UpdateQuery) GetAlias() string

GetAlias returns the alias of the UpdateQuery.

func (UpdateQuery) GetName

func (q UpdateQuery) GetName() string

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

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

func (q UpdateQuery) ToSQL() (string, []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 {
	// Toplevel indicates if the variadic predicate is the top level predicate
	// i.e. it does not need enclosing brackets
	Toplevel   bool
	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 by the AND operator.

func Or

func Or(predicates ...Predicate) VariadicPredicate

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

func (VariadicPredicate) AppendSQLExclude

func (p VariadicPredicate) AppendSQLExclude(buf Buffer, args *[]interface{}, 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 {
	Nested   bool
	Alias    string
	Operator VariadicQueryOperator
	Queries  []Query
}

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 by the EXCEPT operator.

func ExceptAll

func ExceptAll(queries ...Query) VariadicQuery

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

func Intersect

func Intersect(queries ...Query) VariadicQuery

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

func IntersectAll

func IntersectAll(queries ...Query) VariadicQuery

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

func Union

func Union(queries ...Query) VariadicQuery

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

func UnionAll

func UnionAll(queries ...Query) VariadicQuery

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

func (VariadicQuery) AppendSQL

func (q VariadicQuery) AppendSQL(buf Buffer, args *[]interface{})

AppendSQL marshals the VariadicQuery into a buffer and args slice.

func (VariadicQuery) As

func (q VariadicQuery) As(alias string) VariadicQuery

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

func (VariadicQuery) Get

func (q VariadicQuery) Get(fieldName string) CustomField

Get returns a Field from the VariadicQuery, identified by fieldName.

func (VariadicQuery) GetAlias

func (q VariadicQuery) GetAlias() string

GetAlias returns the alias of the VariadicQuery.

func (VariadicQuery) GetName

func (q VariadicQuery) GetName() string

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

func (VariadicQuery) NestThis

func (q VariadicQuery) NestThis() Query

NestThis indicates to the VariadicQuery that it is nested.

func (VariadicQuery) ToSQL

func (q 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
	RenderName        bool
	PartitionByFields Fields
	OrderByFields     Fields
	FrameDefinition   string
}

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 Buffer, args *[]interface{})

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 Buffer, args *[]interface{})

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