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: 16 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSQLDisplay

func AppendSQLDisplay(arg interface{}) string

AppendSQLRowResult

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 DollarInterpolate

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

DollarInterpolate interpolates the dollar $1 ($2, $3 etc) 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 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(arg interface{}) string

TODO: write a version that takes in a buffer and writes into it instead

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 QuestionToDollarPlaceholders

func QuestionToDollarPlaceholders(buf Buffer, query string)

QuestionToDollarPlaceholders will replace all MySQL style ? with Postgres style incrementing placeholders i.e. $1, $2, $3 etc. To escape a literal question mark ? , use two question marks ?? instead.

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.

func SelectDistinctOn

func SelectDistinctOn(distinctFields ...Field) func(...Field) SelectQuery

SelectDistinctOn creates a new SelectQuery.

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{})

ToSQL returns the name of the parent CTE the AliasedCTE was derived from. There is no need to provide the alias, as the caller of ToSQL() should be responsible for calling GetAlias() as well.

func (AliasedCTE) Get

func (cte AliasedCTE) Get(fieldName string) CustomField

Get returns a Field from the AliasedCTE identified by fieldName. No checks are done to see if the fieldName really exists in the AliasedCTE at all, AliasedCTE simply prepends its own alias to the fieldName.

func (AliasedCTE) GetAlias

func (cte AliasedCTE) GetAlias() string

GetAlias implements the Table interface. It returns the alias of the AliasedCTE.

func (AliasedCTE) GetName

func (cte AliasedCTE) GetName() string

GetAlias implements the Table interface. It returns the name of the parent CTE.

type ArrayField

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

ArrayField either represents an ARRAY column, or a literal slice value.

func Array

func Array(slice interface{}) ArrayField

Array returns a new ArrayField representing a literal string value.

func NewArrayField

func NewArrayField(name string, table Table) ArrayField

NewArrayField returns a new ArrayField representing an array column.

func (ArrayField) AppendSQLExclude

func (f ArrayField) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

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

func (ArrayField) As

func (f ArrayField) As(alias string) ArrayField

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

func (ArrayField) Asc

func (f ArrayField) Asc() ArrayField

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

func (ArrayField) Concat

func (f ArrayField) Concat(field ArrayField) Field

Concat concatenates the object ArrayField to the subject ArrayField.

func (ArrayField) ContainedBy

func (f ArrayField) ContainedBy(field ArrayField) Predicate

Contains checks whether the subject ArrayField is contained by the object ArrayField.

func (ArrayField) Contains

func (f ArrayField) Contains(field ArrayField) Predicate

Contains checks whether the subject ArrayField contains the object ArrayField.

func (ArrayField) Desc

func (f ArrayField) Desc() ArrayField

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

func (ArrayField) Eq

func (f ArrayField) Eq(field ArrayField) Predicate

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

func (ArrayField) Ge

func (f ArrayField) Ge(field ArrayField) Predicate

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

func (ArrayField) GetAlias

func (f ArrayField) GetAlias() string

GetAlias implements the Field interface. It returns the Alias of the ArrayField.

func (ArrayField) GetName

func (f ArrayField) GetName() string

GetName implements the Field interface. It returns the Name of the ArrayField.

func (ArrayField) Gt

func (f ArrayField) Gt(field ArrayField) Predicate

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

func (ArrayField) IsNotNull

func (f ArrayField) IsNotNull() Predicate

IsNotNull returns an 'X IS NOT NULL' Predicate.

func (ArrayField) IsNull

func (f ArrayField) IsNull() Predicate

IsNull returns an 'X IS NULL' Predicate.

func (ArrayField) Le

func (f ArrayField) Le(field ArrayField) Predicate

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

func (ArrayField) Lt

func (f ArrayField) Lt(field ArrayField) Predicate

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

func (ArrayField) Ne

func (f ArrayField) Ne(field ArrayField) Predicate

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

func (ArrayField) NullsFirst

func (f ArrayField) NullsFirst() ArrayField

NullsFirst returns a new ArrayField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (ArrayField) NullsLast

func (f ArrayField) NullsLast() ArrayField

NullsLast returns a new ArrayField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (ArrayField) Overlaps

func (f ArrayField) Overlaps(field ArrayField) Predicate

Overlaps checks whether the subject ArrayField and the object ArrayField have any values in common.

func (ArrayField) Set

func (f ArrayField) Set(value ArrayField) FieldAssignment

SetArray returns a FieldAssignment associating the ArrayField to the value i.e. 'field = value'. It only accepts ArrayField.

func (ArrayField) String

func (f ArrayField) String() string

String implements the fmt.Stringer interface. It returns the string representation of an ArrayField.

type Assignment

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

type Assignments

type Assignments []Assignment

Assignments is a list of Assignments, when translated to SQL it looks something like "SET field1 = value1, field2 = value2, etc...".

func (Assignments) AppendSQLExclude

func (assignments Assignments) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

AppendSQLExclude will write the Assignments into the buffer and args as described in the Assignments description.

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(table 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) 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) SelectDistinctOn

func (q BaseQuery) SelectDistinctOn(distinctFields ...Field) func(...Field) SelectQuery

SelectDistinctOn 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 BYTEA 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 BYTEA 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 implements the Field interface. It returns the Alias of the BinaryField.

func (BinaryField) GetName

func (f BinaryField) GetName() string

GetName implements the Field interface. It 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 returns a new BooleanField with the new field Alias 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 implements the Field interface. It returns the Alias of the BooleanField.

func (BooleanField) GetName

func (f BooleanField) GetName() string

GetName implements the Field interface. It 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 implements the Predicate interface.

func (BooleanField) NullsFirst

func (f BooleanField) NullsFirst() BooleanField

NullsFirst returns a new BooleanField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (BooleanField) NullsLast

func (f BooleanField) NullsLast() BooleanField

NullsLast returns a new BooleanField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

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 implements the fmt.Stringer interface. It returns the string representation of a BooleanField.

type Buffer

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

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{})

ToSQL simply returns the name of the CTE.

func (CTE) As

func (cte CTE) As(alias string) AliasedCTE

As returns a an Aliased CTE derived from the parent CTE that it was called on.

func (CTE) Get

func (cte CTE) Get(fieldName string) CustomField

Get returns a Field from the CTE identified by fieldName. No checks are done to see if the fieldName really exists in the CTE at all, CTE simply prepends its own name to the fieldName.

func (CTE) GetAlias

func (cte CTE) GetAlias() string

GetAlias implements the Table interface. It always returns an empty string, because CTEs do not have aliases (only AliasedCTEs do).

func (CTE) GetName

func (cte CTE) GetName() string

GetAlias implements the Table interface. It 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 will write the CTE clause into the buffer and args. If there are no CTEs to be written, it will simply write nothing. It returns a flag indicating whether it wrote anything into the buffer.

type CustomAssignment

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

func (CustomAssignment) AppendSQLExclude

func (set CustomAssignment) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

func (CustomAssignment) AssertAssignment

func (set CustomAssignment) AssertAssignment()

type CustomField

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

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

func Excluded

func Excluded(field Field) CustomField

func Fieldf

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

Fieldf is a CustomField constructor.

func (CustomField) AppendSQLExclude

func (f CustomField) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

AppendSQL marshals the CustomField into an SQL query and args as described in the CustomField struct description.

func (CustomField) As

func (f CustomField) As(alias string) CustomField

As returns a new CustomField with the new alias 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 implements the Field interface. It returns the alias of thee CustomField.

func (CustomField) GetName

func (f CustomField) GetName() string

GetName implements the Field interface. It 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) NullsFirst

func (f CustomField) NullsFirst() CustomField

NullsFirst returns a new CustomField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (CustomField) NullsLast

func (f CustomField) NullsLast() CustomField

NullsLast returns a new CustomField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

func (CustomField) String

func (f CustomField) String() string

String implements the fmt.Stringer interface. It returns the string representation of a 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 as defined by its Format string. Values are interpolated into the Format string as described in the (CustomPredicate).CustomSprintf function.

func Exists

func Exists(query Query) CustomPredicate

func Predicatef

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

func (CustomPredicate) AppendSQLExclude

func (p CustomPredicate) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

ToSQL marshals the CustomPredicate into an SQL query.

func (CustomPredicate) As

func (CustomPredicate) GetAlias

func (p CustomPredicate) GetAlias() string

GetAlias implements the Field interface.

func (CustomPredicate) GetName

func (p CustomPredicate) GetName() string

GetName implements the Field interface.

func (CustomPredicate) Not

func (p CustomPredicate) Not() Predicate

Not implements the Predicate interface.

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 as defined by its Format string. Values are interpolated into the Format string as described in the (CustomQuery).CustomSprintf function.

The difference between CustomTable and CustomQuery is that CustomTable is not meant for writing full queries, because it does not do any form of placeholder ?, ?, ? -> $1, $2, $3 etc rebinding.

func Queryf

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

func (CustomQuery) AppendSQL

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

AppendSQL marshals the CustomQuery into an SQL query.

func (CustomQuery) As

func (q CustomQuery) As(alias string) CustomQuery

As returns a new CustomQuery with the new alias i.e. 'query AS Alias'.

func (CustomQuery) GetAlias

func (q CustomQuery) GetAlias() string

GetAlias implements the Table interface. It returns the alias of the CustomQuery.

func (CustomQuery) GetName

func (q CustomQuery) GetName() string

GetName implements the Table interface. It returns the name of the CustomQuery.

func (CustomQuery) NestThis

func (q CustomQuery) NestThis() Query

NestThis implements the Query interface.

func (CustomQuery) ToSQL

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

ToSQL implements the Query interface.

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

type DeleteQuery

type DeleteQuery struct {
	Nested bool
	Alias  string
	// WITH
	CTEs CTEs
	// DELETE FROM
	FromTable BaseTable
	// USING
	UsingTable Table
	JoinTables JoinTables
	// WHERE
	WherePredicate VariadicPredicate
	// RETURNING
	ReturningFields Fields
	// DB
	DB          DB
	Mapper      func(*Row)
	Accumulator func()
	// Logging
	Log     Logger
	LogFlag LogFlag
	LogSkip int
}

func DeleteFrom

func DeleteFrom(table BaseTable) DeleteQuery

func (DeleteQuery) AppendSQL

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

func (DeleteQuery) As

func (q DeleteQuery) As(alias string) DeleteQuery

func (DeleteQuery) CustomJoin

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

func (DeleteQuery) DeleteFrom

func (q DeleteQuery) DeleteFrom(table BaseTable) DeleteQuery

func (DeleteQuery) Exec

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

func (DeleteQuery) ExecContext

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

func (DeleteQuery) Fetch

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

func (DeleteQuery) FetchContext

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

func (DeleteQuery) FullJoin

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

func (DeleteQuery) Get

func (q DeleteQuery) Get(fieldName string) CustomField

func (DeleteQuery) GetAlias

func (q DeleteQuery) GetAlias() string

func (DeleteQuery) GetName

func (q DeleteQuery) GetName() string

func (DeleteQuery) Join

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

func (DeleteQuery) LeftJoin

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

func (DeleteQuery) NestThis

func (q DeleteQuery) NestThis() Query

func (DeleteQuery) Returning

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

func (DeleteQuery) ReturningOne

func (q DeleteQuery) ReturningOne() DeleteQuery

func (DeleteQuery) ReturningRowx

func (q DeleteQuery) ReturningRowx(mapper func(*Row)) DeleteQuery

func (DeleteQuery) Returningx

func (q DeleteQuery) Returningx(mapper func(*Row), accumulator func()) DeleteQuery

func (DeleteQuery) RightJoin

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

func (DeleteQuery) ToSQL

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

func (DeleteQuery) Using

func (q DeleteQuery) Using(table Table) DeleteQuery

func (DeleteQuery) Where

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

func (DeleteQuery) With

func (q DeleteQuery) With(ctes ...CTE) 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 will write the FieldAssignment into the buffer and args as described in the Assignments description.

func (FieldAssignment) AssertAssignment

func (set FieldAssignment) AssertAssignment()

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)

ToSQL returns the underlying string of the FieldLiteral.

func (FieldLiteral) GetAlias

func (f FieldLiteral) GetAlias() string

GetAlias implements the Field interface. It always returns an empty string because FieldLiterals do not have aliases.

func (FieldLiteral) GetName

func (f FieldLiteral) GetName() string

GetName implements the Field interface. It returns the FieldLiteral's underlying string as the name.

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 will write the a slice of Fields into the buffer and args as described in the Fields description. The list of table qualifiers to be excluded is propagated down to the individual 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 FunctionInfo

type FunctionInfo struct {
	Schema    string
	Name      string
	Alias     string
	Arguments []interface{}
}

func Functionf

func Functionf(name string, args ...interface{}) *FunctionInfo

func (*FunctionInfo) AppendSQL

func (f *FunctionInfo) AppendSQL(buf Buffer, args *[]interface{})

AppendSQL adds the fully qualified function call into the buffer.

func (*FunctionInfo) AppendSQLExclude

func (f *FunctionInfo) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

AppendSQLExclude adds the fully qualified function call into the buffer.

func (*FunctionInfo) GetAlias

func (f *FunctionInfo) GetAlias() string

GetAlias implements the Table interface. It returns the alias of the FunctionInfo.

func (*FunctionInfo) GetName

func (f *FunctionInfo) GetName() string

GetName implements the Table interface. It returns the name of the FunctionInfo.

type InsertQuery

type InsertQuery struct {
	Nested bool
	Alias  string
	// WITH
	CTEs CTEs
	// INSERT INTO
	IntoTable     BaseTable
	InsertColumns Fields
	// VALUES
	RowValues RowValues
	// SELECT
	SelectQuery *SelectQuery
	// ON CONFLICT
	HandleConflict      bool
	ConflictFields      Fields
	ConflictPredicate   VariadicPredicate
	ConflictConstraint  string
	Resolution          Assignments
	ResolutionPredicate VariadicPredicate
	// RETURNING
	ReturningFields Fields
	// DB
	DB          DB
	Mapper      func(*Row)
	Accumulator func()
	// Logging
	Log     Logger
	LogFlag LogFlag
	LogSkip int
}

func InsertInto

func InsertInto(table BaseTable) InsertQuery

func (InsertQuery) AppendSQL

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

func (InsertQuery) As

func (q InsertQuery) As(alias string) InsertQuery

func (InsertQuery) Columns

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

func (InsertQuery) Exec

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

func (InsertQuery) ExecContext

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

func (InsertQuery) Fetch

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

func (InsertQuery) FetchContext

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

func (InsertQuery) GetAlias

func (q InsertQuery) GetAlias() string

func (InsertQuery) GetName

func (q InsertQuery) GetName() string

func (InsertQuery) InsertInto

func (q InsertQuery) InsertInto(table BaseTable) InsertQuery

func (InsertQuery) InsertRow

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

func (InsertQuery) NestThis

func (q InsertQuery) NestThis() Query

func (InsertQuery) OnConflict

func (q InsertQuery) OnConflict(fields ...Field) insertConflict

func (InsertQuery) OnConflictOnConstraint

func (q InsertQuery) OnConflictOnConstraint(name string) insertConflict

func (InsertQuery) Returning

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

func (InsertQuery) ReturningOne

func (q InsertQuery) ReturningOne() InsertQuery

func (InsertQuery) ReturningRowx

func (q InsertQuery) ReturningRowx(mapper func(*Row)) InsertQuery

func (InsertQuery) Returningx

func (q InsertQuery) Returningx(mapper func(*Row), accumulator func()) InsertQuery

func (InsertQuery) Select

func (q InsertQuery) Select(selectQuery SelectQuery) InsertQuery

func (InsertQuery) ToSQL

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

func (InsertQuery) Values

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

func (InsertQuery) Where

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

func (InsertQuery) With

func (q InsertQuery) With(ctes ...CTE) 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)

AppendSQL marshals the JSONField into an SQL query and args as described in the JSONField internal struct comments.

func (JSONField) As

func (f JSONField) As(alias string) JSONField

As returns a new JSONField with the new field Alias 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 implements the Field interface. It returns the Alias of the JSONField.

func (JSONField) GetName

func (f JSONField) GetName() string

GetName implements the Field interface. It 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) NullsFirst

func (f JSONField) NullsFirst() JSONField

NullsFirst returns a new JSONField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (JSONField) NullsLast

func (f JSONField) NullsLast() JSONField

NullsLast returns a new JSONField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

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 implements the fmt.Stringer interface. It returns the string representation of a 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 constructs a new JoinTable. Meant to be used if you want to do a custom join like CROSS JOIN, NATURAL JOIN, LEFT JOIN LATERAL etc.

func FullJoin

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

func Join

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

func LeftJoin

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

func RightJoin

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

func (JoinTable) AppendSQL

func (join JoinTable) AppendSQL(buf Buffer, args *[]interface{})

type JoinTables

type JoinTables []JoinTable

JoinTables is a list of JoinTables.

func (JoinTables) AppendSQL

func (joins JoinTables) AppendSQL(buf Buffer, args *[]interface{})

AppendSQL will write the JOIN clause into the buffer and args. If there are no JoinTables it simply writes nothing into the buffer. It returns a flag indicating whether anything was written into the buffer.

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 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 NumberFieldf

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

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 an SQL query and args as described in the NumberField internal struct comments.

func (NumberField) As

func (f NumberField) As(alias string) NumberField

As returns a new NumberField with the new field Alias 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 implements the Field interface. It returns the Alias of the NumberField.

func (NumberField) GetName

func (f NumberField) GetName() string

GetName implements the Field interface. It 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) NullsFirst

func (f NumberField) NullsFirst() NumberField

NullsFirst returns a new NumberField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (NumberField) NullsLast

func (f NumberField) NullsLast() NumberField

NullsLast returns a new NumberField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

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 implements the fmt.Stringer interface. It returns the string representation of a 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

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

func (r *Row) ScanArray(slice interface{}, field Field)

ScanArray accepts a pointer to a slice and scans a postgres array into it. Only []bool, []float64, []int64 or []string slices are supported.

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{}

func (RowValue) AppendSQL

func (r RowValue) AppendSQL(buf Buffer, args *[]interface{})

func (RowValue) AppendSQLExclude

func (r RowValue) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

func (RowValue) In

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

func (RowValue) Set

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

type RowValues

type RowValues []RowValue

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

func (RowValues) AppendSQL

func (rs RowValues) AppendSQL(buf Buffer, args *[]interface{})

AppendSQL will write the VALUES clause into the buffer and args as described in the RowValues description. If there are no values it will not write anything into the buffer. It returns a flag indicating whether anything was written into the buffer.

type SelectQuery

type SelectQuery struct {
	Nested bool
	Alias  string
	// WITH
	CTEs CTEs
	// SELECT
	SelectType   SelectType
	SelectFields Fields
	DistinctOn   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) Exec

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

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

func (SelectQuery) ExecContext

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

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

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

func (q SelectQuery) SelectDistinctOn(distinctFields ...Field) func(...Field) SelectQuery

SelectDistinctOn adds the distinctFields to the DistinctOn fields and 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"
	SelectTypeDistinctOn SelectType = "SELECT DISTINCT ON"
)

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 an SQL query and args as described in the StringField internal struct comments.

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 implements the Field interface. It returns the Alias of the StringField.

func (StringField) GetName

func (f StringField) GetName() string

GetName implements the Field interface. It 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) ILikeString

func (f StringField) ILikeString(s string) Predicate

LikeString returns an 'A ILIKE B' 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) NotILikeString

func (f StringField) NotILikeString(s string) Predicate

NotLikeString returns an 'A NOT ILIKE B' 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) NullsFirst

func (f StringField) NullsFirst() StringField

NullsFirst returns a new StringField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (StringField) NullsLast

func (f StringField) NullsLast() StringField

NullsLast returns a new StringField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

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 implements the fmt.Stringer interface. It returns the string representation of a StringField.

type Table

type Table interface {
	AppendSQL(buf Buffer, args *[]interface{})
	GetAlias() string
	GetName() string // Table name must exclude the schema (if any)
}

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{})

AppendSQL adds the fully qualified table name into the buffer.

func (*TableInfo) AssertBaseTable

func (tbl *TableInfo) AssertBaseTable()

AssertBaseTable implements the BaseTable interface.

func (*TableInfo) GetAlias

func (tbl *TableInfo) GetAlias() string

GetAlias implements the Table interface. It returns the alias from the TableInfo.

func (*TableInfo) GetName

func (tbl *TableInfo) GetName() string

GetName implements the Table interface. It returns the name from 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) BetweenSymmetricTime

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

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

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 implements the Field interface. It returns the Alias of the TimeField.

func (TimeField) GetName

func (f TimeField) GetName() string

GetName implements the Field interface. It 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) NotBetweenSymmetricTime

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

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

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

func (f TimeField) NullsFirst() TimeField

NullsFirst returns a new TimeField indicating that it should be ordered with nulls first i.e. 'ORDER BY field NULLS FIRST'.

func (TimeField) NullsLast

func (f TimeField) NullsLast() TimeField

NullsLast returns a new TimeField indicating that it should be ordered with nulls last i.e. 'ORDER BY field NULLS LAST'.

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 implements the fmt.Stringer interface. It returns the string representation of a TimeField.

type UpdateQuery

type UpdateQuery struct {
	Nested bool
	Alias  string
	// WITH
	CTEs CTEs
	// UPDATE
	UpdateTable BaseTable
	// SET
	Assignments Assignments
	// FROM
	FromTable  Table
	JoinTables JoinTables
	// WHERE
	WherePredicate VariadicPredicate
	// RETURNING
	ReturningFields Fields
	// DB
	DB          DB
	Mapper      func(*Row)
	Accumulator func()
	// Logging
	Log     Logger
	LogFlag LogFlag
	LogSkip int
}

func Update

func Update(table BaseTable) UpdateQuery

func (UpdateQuery) AppendSQL

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

func (UpdateQuery) As

func (q UpdateQuery) As(alias string) UpdateQuery

func (UpdateQuery) CustomJoin

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

func (UpdateQuery) Exec

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

func (UpdateQuery) ExecContext

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

func (UpdateQuery) Fetch

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

func (UpdateQuery) FetchContext

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

func (UpdateQuery) From

func (q UpdateQuery) From(table Table) UpdateQuery

func (UpdateQuery) FullJoin

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

func (UpdateQuery) GetAlias

func (q UpdateQuery) GetAlias() string

func (UpdateQuery) GetName

func (q UpdateQuery) GetName() string

func (UpdateQuery) Join

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

func (UpdateQuery) LeftJoin

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

func (UpdateQuery) NestThis

func (q UpdateQuery) NestThis() Query

func (UpdateQuery) Returning

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

func (UpdateQuery) ReturningOne

func (q UpdateQuery) ReturningOne() UpdateQuery

func (UpdateQuery) ReturningRowx

func (q UpdateQuery) ReturningRowx(mapper func(*Row)) UpdateQuery

func (UpdateQuery) Returningx

func (q UpdateQuery) Returningx(mapper func(*Row), accumulator func()) UpdateQuery

func (UpdateQuery) RightJoin

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

func (UpdateQuery) Set

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

func (UpdateQuery) ToSQL

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

func (UpdateQuery) Update

func (q UpdateQuery) Update(table BaseTable) UpdateQuery

func (UpdateQuery) Where

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

func (UpdateQuery) With

func (q UpdateQuery) With(ctes ...CTE) 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

func Or

func Or(predicates ...Predicate) VariadicPredicate

func (VariadicPredicate) AppendSQLExclude

func (p VariadicPredicate) AppendSQLExclude(buf Buffer, args *[]interface{}, excludedTableQualifiers []string)

ToSQL marshals the VariadicPredicate into an SQL query and args as described in the VariadicPredicate struct description.

func (VariadicPredicate) GetAlias

func (p VariadicPredicate) GetAlias() string

GetAlias implements the Field interface.

func (VariadicPredicate) GetName

func (p VariadicPredicate) GetName() string

GetName implements the Field interface.

func (VariadicPredicate) Not

func (p VariadicPredicate) Not() Predicate

Not implements the Predicate interface.

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

Possible VariadicOperators

type VariadicQuery

type VariadicQuery struct {
	Nested   bool
	Alias    string
	Operator VariadicQueryOperator
	Queries  []Query
}

func Except

func Except(queries ...Query) VariadicQuery

func ExceptAll

func ExceptAll(queries ...Query) VariadicQuery

func Intersect

func Intersect(queries ...Query) VariadicQuery

func IntersectAll

func IntersectAll(queries ...Query) VariadicQuery

func Union

func Union(queries ...Query) VariadicQuery

func UnionAll

func UnionAll(queries ...Query) VariadicQuery

func (VariadicQuery) AppendSQL

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

func (VariadicQuery) As

func (q VariadicQuery) As(alias string) VariadicQuery

func (VariadicQuery) Get

func (q VariadicQuery) Get(fieldName string) CustomField

func (VariadicQuery) GetAlias

func (q VariadicQuery) GetAlias() string

func (VariadicQuery) GetName

func (q VariadicQuery) GetName() string

func (VariadicQuery) NestThis

func (q VariadicQuery) NestThis() Query

func (VariadicQuery) ToSQL

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

type VariadicQueryOperator

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

type Window

type Window struct {
	WindowName        string
	RenderName        bool
	PartitionByFields Fields
	OrderByFields     Fields
	FrameDefinition   string
}

func OrderBy

func OrderBy(fields ...Field) Window

func PartitionBy

func PartitionBy(fields ...Field) Window

func (Window) AppendSQL

func (w Window) AppendSQL(buf Buffer, args *[]interface{})

func (Window) As

func (w Window) As(name string) Window

func (Window) Frame

func (w Window) Frame(frameDefinition string) Window

func (Window) Name

func (w Window) Name() Window

func (Window) OrderBy

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

func (Window) PartitionBy

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

type Windows

type Windows []Window

func (Windows) AppendSQL

func (ws Windows) AppendSQL(buf Buffer, args *[]interface{})

Jump to

Keyboard shortcuts

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