Documentation ¶
Index ¶
- type Assignment
- type Assignments
- type BaseQuery
- func (q BaseQuery) DeleteFrom(tables ...BaseTable) DeleteQuery
- func (q BaseQuery) From(table Table) SelectQuery
- func (q BaseQuery) InsertIgnoreInto(table BaseTable) InsertQuery
- func (q BaseQuery) InsertInto(table BaseTable) InsertQuery
- func (q BaseQuery) Select(fields ...Field) SelectQuery
- func (q BaseQuery) SelectAll() SelectQuery
- func (q BaseQuery) SelectCount() SelectQuery
- func (q BaseQuery) SelectDistinct(fields ...Field) SelectQuery
- func (q BaseQuery) SelectOne() SelectQuery
- func (q BaseQuery) SelectRowx(mapper func(*Row)) SelectQuery
- func (q BaseQuery) Selectx(mapper func(*Row), accumulator func()) SelectQuery
- func (q BaseQuery) Union(queries ...Query) VariadicQuery
- func (q BaseQuery) UnionAll(queries ...Query) VariadicQuery
- func (q BaseQuery) Update(table BaseTable) UpdateQuery
- func (q BaseQuery) With(CTEs ...CTE) BaseQuery
- func (q BaseQuery) WithDB(db DB) BaseQuery
- func (q BaseQuery) WithDefaultLog(flag LogFlag) BaseQuery
- type BaseTable
- type BinaryField
- func (f BinaryField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f BinaryField) GetAlias() string
- func (f BinaryField) GetName() string
- func (f BinaryField) IsNotNull() Predicate
- func (f BinaryField) IsNull() Predicate
- func (f BinaryField) Set(v interface{}) FieldAssignment
- func (f BinaryField) SetBytes(b []byte) FieldAssignment
- type BooleanField
- func (f BooleanField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f BooleanField) As(alias string) BooleanField
- func (f BooleanField) Asc() BooleanField
- func (f BooleanField) Desc() BooleanField
- func (f BooleanField) Eq(field BooleanField) Predicate
- func (f BooleanField) GetAlias() string
- func (f BooleanField) GetName() string
- func (f BooleanField) IsNotNull() Predicate
- func (f BooleanField) IsNull() Predicate
- func (f BooleanField) Ne(field BooleanField) Predicate
- func (f BooleanField) Not() Predicate
- func (f BooleanField) Set(val interface{}) FieldAssignment
- func (f BooleanField) SetBool(val bool) FieldAssignment
- func (f BooleanField) String() string
- type CTE
- func (cte CTE) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (cte CTE) As(alias string) CTE
- func (cte CTE) GetAlias() string
- func (cte CTE) GetColumns() []string
- func (cte CTE) GetName() string
- func (cte CTE) GetQuery() Query
- func (cte *CTE) Initial(query Query) IntermediateCTE
- func (cte CTE) IsRecursive() bool
- type Column
- func (col *Column) Set(field Field, value interface{})
- func (col *Column) SetBool(field BooleanField, value bool)
- func (col *Column) SetFloat64(field NumberField, value float64)
- func (col *Column) SetInt(field NumberField, value int)
- func (col *Column) SetInt64(field NumberField, value int64)
- func (col *Column) SetString(field StringField, value string)
- func (col *Column) SetTime(field TimeField, value time.Time)
- type CustomAssignment
- type CustomField
- func Fieldf(format string, values ...interface{}) CustomField
- func FirstValueOver(field interface{}, window Window) CustomField
- func LagOver(field interface{}, offset interface{}, fallback interface{}, window Window) CustomField
- func LastValueOver(field interface{}, window Window) CustomField
- func LeadOver(field interface{}, offset interface{}, fallback interface{}, window Window) CustomField
- func NthValueOver(field interface{}, n int, window Window) CustomField
- func Values(field Field) CustomField
- func (f CustomField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f CustomField) As(alias string) CustomField
- func (f CustomField) Asc() CustomField
- func (f CustomField) Desc() CustomField
- func (f CustomField) Eq(v interface{}) Predicate
- func (f CustomField) Ge(v interface{}) Predicate
- func (f CustomField) GetAlias() string
- func (f CustomField) GetName() string
- func (f CustomField) Gt(v interface{}) Predicate
- func (f CustomField) In(v interface{}) Predicate
- func (f CustomField) IsNotNull() Predicate
- func (f CustomField) IsNull() Predicate
- func (f CustomField) Le(v interface{}) Predicate
- func (f CustomField) Lt(v interface{}) Predicate
- func (f CustomField) Ne(v interface{}) Predicate
- func (f CustomField) String() string
- type CustomPredicate
- type DB
- type DeleteQuery
- func (q DeleteQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (q DeleteQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) DeleteQuery
- func (q DeleteQuery) DeleteFrom(tables ...BaseTable) DeleteQuery
- func (q DeleteQuery) Exec(db DB, flag ExecFlag) (rowsAffected int64, err error)
- func (q DeleteQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (rowsAffected int64, err error)
- func (q DeleteQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
- func (q DeleteQuery) Join(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
- func (q DeleteQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
- func (q DeleteQuery) Limit(limit int) DeleteQuery
- func (q DeleteQuery) NestThis() Query
- func (q DeleteQuery) OrderBy(fields ...Field) DeleteQuery
- func (q DeleteQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
- func (q DeleteQuery) ToSQL() (string, []interface{})
- func (q DeleteQuery) Using(table Table) DeleteQuery
- func (q DeleteQuery) Where(predicates ...Predicate) DeleteQuery
- func (q DeleteQuery) With(ctes ...CTE) DeleteQuery
- type EnumField
- type ExecFlag
- type ExitCode
- type Field
- type FieldAssignment
- type FieldLiteral
- type Fields
- type InsertQuery
- func (q InsertQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (q InsertQuery) Columns(fields ...Field) InsertQuery
- func (q InsertQuery) Exec(db DB, flag ExecFlag) (lastInsertID, rowsAffected int64, err error)
- func (q InsertQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (lastInsertID, rowsAffected int64, err error)
- func (q InsertQuery) InsertIgnoreInto(table BaseTable) InsertQuery
- func (q InsertQuery) InsertInto(table BaseTable) InsertQuery
- func (q InsertQuery) NestThis() Query
- func (q InsertQuery) OnDuplicateKeyUpdate(assignments ...Assignment) InsertQuery
- func (q InsertQuery) Select(selectQuery SelectQuery) InsertQuery
- func (q InsertQuery) ToSQL() (query string, args []interface{})
- func (q InsertQuery) Values(values ...interface{}) InsertQuery
- func (q InsertQuery) Valuesx(mapper func(*Column)) InsertQuery
- type IntermediateCTE
- type JSONField
- func (f JSONField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f JSONField) As(alias string) JSONField
- func (f JSONField) Asc() JSONField
- func (f JSONField) Desc() JSONField
- func (f JSONField) GetAlias() string
- func (f JSONField) GetName() string
- func (f JSONField) IsNotNull() Predicate
- func (f JSONField) IsNull() Predicate
- func (f JSONField) Set(value interface{}) FieldAssignment
- func (f JSONField) SetJSON(value interface{}) FieldAssignment
- func (f JSONField) SetValue(value driver.Valuer) FieldAssignment
- func (f JSONField) String() string
- type JoinTable
- func CustomJoin(joinType JoinType, table Table, predicates ...Predicate) JoinTable
- func FullJoin(table Table, predicates ...Predicate) JoinTable
- func Join(table Table, predicates ...Predicate) JoinTable
- func LeftJoin(table Table, predicates ...Predicate) JoinTable
- func RightJoin(table Table, predicates ...Predicate) JoinTable
- type JoinTables
- type JoinType
- type LogFlag
- type Logger
- type NumberField
- func Avg(field interface{}) NumberField
- func AvgOver(field interface{}, window Window) NumberField
- func Count() NumberField
- func CountOver(window Window) NumberField
- func CumeDistOver(window Window) NumberField
- func DenseRankOver(window Window) NumberField
- func Float64(num float64) NumberField
- func Int(num int) NumberField
- func Int64(num int64) NumberField
- func Max(field interface{}) NumberField
- func MaxOver(field interface{}, window Window) NumberField
- func Min(field interface{}) NumberField
- func MinOver(field interface{}, window Window) NumberField
- func NewNumberField(name string, table Table) NumberField
- func NtileOver(n int, window Window) NumberField
- func NumberFieldf(format string, values ...interface{}) NumberField
- func PercentRankOver(window Window) NumberField
- func RankOver(window Window) NumberField
- func RowNumberOver(window Window) NumberField
- func Sum(field interface{}) NumberField
- func SumOver(field interface{}, window Window) NumberField
- func (f NumberField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f NumberField) As(alias string) NumberField
- func (f NumberField) Asc() NumberField
- func (f NumberField) Desc() NumberField
- func (f NumberField) Eq(field NumberField) Predicate
- func (f NumberField) EqFloat64(num float64) Predicate
- func (f NumberField) EqInt(num int) Predicate
- func (f NumberField) Ge(field NumberField) Predicate
- func (f NumberField) GeFloat64(num float64) Predicate
- func (f NumberField) GeInt(num int) Predicate
- func (f NumberField) GetAlias() string
- func (f NumberField) GetName() string
- func (f NumberField) Gt(field NumberField) Predicate
- func (f NumberField) GtFloat64(num float64) Predicate
- func (f NumberField) GtInt(num int) Predicate
- func (f NumberField) In(v interface{}) Predicate
- func (f NumberField) IsNotNull() Predicate
- func (f NumberField) IsNull() Predicate
- func (f NumberField) Le(field NumberField) Predicate
- func (f NumberField) LeFloat64(num float64) Predicate
- func (f NumberField) LeInt(num int) Predicate
- func (f NumberField) Lt(field NumberField) Predicate
- func (f NumberField) LtFloat64(num float64) Predicate
- func (f NumberField) LtInt(num int) Predicate
- func (f NumberField) Ne(field NumberField) Predicate
- func (f NumberField) NeFloat64(num float64) Predicate
- func (f NumberField) NeInt(num int) Predicate
- func (f NumberField) Set(val interface{}) FieldAssignment
- func (f NumberField) SetFloat64(num float64) FieldAssignment
- func (f NumberField) SetInt(num int) FieldAssignment
- func (f NumberField) SetInt64(num int64) FieldAssignment
- func (f NumberField) String() string
- type Predicate
- type PredicateCase
- type PredicateCases
- func (f PredicateCases) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f PredicateCases) As(alias string) PredicateCases
- func (f PredicateCases) Else(fallback interface{}) PredicateCases
- func (f PredicateCases) GetAlias() string
- func (f PredicateCases) GetName() string
- func (f PredicateCases) When(predicate Predicate, result interface{}) PredicateCases
- type Query
- type Row
- func (r *Row) Bool(predicate Predicate) bool
- func (r *Row) BoolValid(predicate Predicate) bool
- func (r *Row) Float64(field NumberField) float64
- func (r *Row) Float64Valid(field NumberField) bool
- func (r *Row) Int(field NumberField) int
- func (r *Row) Int64(field NumberField) int64
- func (r *Row) Int64Valid(field NumberField) bool
- func (r *Row) IntValid(field NumberField) bool
- func (r *Row) NullBool(predicate Predicate) sql.NullBool
- func (r *Row) NullFloat64(field NumberField) sql.NullFloat64
- func (r *Row) NullInt64(field NumberField) sql.NullInt64
- func (r *Row) NullString(field StringField) sql.NullString
- func (r *Row) NullTime(field TimeField) sql.NullTime
- func (r *Row) ScanInto(dest interface{}, field Field)
- func (r *Row) String(field StringField) string
- func (r *Row) StringValid(field StringField) bool
- func (r *Row) Time(field TimeField) time.Time
- func (r *Row) TimeValid(field TimeField) bool
- type RowValue
- func (r RowValue) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (r RowValue) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (r RowValue) In(v interface{}) CustomPredicate
- func (r RowValue) Set(v interface{}) CustomAssignment
- type RowValues
- type SelectQuery
- func (q SelectQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (q SelectQuery) CTE(name string, columns ...string) CTE
- func (q SelectQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) SelectQuery
- func (q SelectQuery) Fetch(db DB) (err error)
- func (q SelectQuery) FetchContext(ctx context.Context, db DB) (err error)
- func (q SelectQuery) From(table Table) SelectQuery
- func (q SelectQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
- func (q SelectQuery) GroupBy(fields ...Field) SelectQuery
- func (q SelectQuery) Having(predicates ...Predicate) SelectQuery
- func (q SelectQuery) Join(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
- func (q SelectQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
- func (q SelectQuery) Limit(limit int) SelectQuery
- func (q SelectQuery) NestThis() Query
- func (q SelectQuery) Offset(offset int) SelectQuery
- func (q SelectQuery) OrderBy(fields ...Field) SelectQuery
- func (q SelectQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
- func (q SelectQuery) Select(fields ...Field) SelectQuery
- func (q SelectQuery) SelectAll() SelectQuery
- func (q SelectQuery) SelectCount() SelectQuery
- func (q SelectQuery) SelectDistinct(fields ...Field) SelectQuery
- func (q SelectQuery) SelectOne() SelectQuery
- func (q SelectQuery) SelectRowx(mapper func(*Row)) SelectQuery
- func (q SelectQuery) Selectx(mapper func(*Row), accumulator func()) SelectQuery
- func (q SelectQuery) Subquery(alias string) Subquery
- func (q SelectQuery) ToSQL() (string, []interface{})
- func (q SelectQuery) Where(predicates ...Predicate) SelectQuery
- func (q SelectQuery) Window(windows ...Window) SelectQuery
- func (q SelectQuery) With(ctes ...CTE) SelectQuery
- type SelectType
- type SimpleCase
- type SimpleCases
- func (f SimpleCases) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f SimpleCases) As(alias string) SimpleCases
- func (f SimpleCases) Else(field Field) SimpleCases
- func (f SimpleCases) GetAlias() string
- func (f SimpleCases) GetName() string
- func (f SimpleCases) When(field Field, result Field) SimpleCases
- type StringField
- func (f StringField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f StringField) As(alias string) StringField
- func (f StringField) Asc() StringField
- func (f StringField) Desc() StringField
- func (f StringField) Eq(field StringField) Predicate
- func (f StringField) EqString(s string) Predicate
- func (f StringField) Ge(field StringField) Predicate
- func (f StringField) GeString(s string) Predicate
- func (f StringField) GetAlias() string
- func (f StringField) GetName() string
- func (f StringField) Gt(field StringField) Predicate
- func (f StringField) GtString(s string) Predicate
- func (f StringField) In(v interface{}) Predicate
- func (f StringField) IsNotNull() Predicate
- func (f StringField) IsNull() Predicate
- func (f StringField) Le(field StringField) Predicate
- func (f StringField) LeString(s string) Predicate
- func (f StringField) LikeString(s string) Predicate
- func (f StringField) Lt(field StringField) Predicate
- func (f StringField) LtString(s string) Predicate
- func (f StringField) Ne(field StringField) Predicate
- func (f StringField) NeString(s string) Predicate
- func (f StringField) NotLikeString(s string) Predicate
- func (f StringField) Set(value interface{}) FieldAssignment
- func (f StringField) SetString(s string) FieldAssignment
- func (f StringField) String() string
- type Subquery
- func (subq Subquery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (subq Subquery) GetAlias() string
- func (subq Subquery) GetName() string
- func (subq Subquery) GetQuery() Query
- func (subq Subquery) NestThis() Query
- func (subq Subquery) ToSQL() (string, []interface{})
- type Table
- type TableInfo
- type TimeField
- func (f TimeField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, ...)
- func (f TimeField) As(alias string) TimeField
- func (f TimeField) Asc() TimeField
- func (f TimeField) Between(start, end TimeField) Predicate
- func (f TimeField) BetweenTime(start, end time.Time) Predicate
- func (f TimeField) Desc() TimeField
- func (f TimeField) Eq(field TimeField) Predicate
- func (f TimeField) EqTime(t time.Time) Predicate
- func (f TimeField) Ge(field TimeField) Predicate
- func (f TimeField) GeTime(t time.Time) Predicate
- func (f TimeField) GetAlias() string
- func (f TimeField) GetName() string
- func (f TimeField) Gt(field TimeField) Predicate
- func (f TimeField) GtTime(t time.Time) Predicate
- func (f TimeField) IsNotNull() Predicate
- func (f TimeField) IsNull() Predicate
- func (f TimeField) Le(field TimeField) Predicate
- func (f TimeField) LeTime(t time.Time) Predicate
- func (f TimeField) Lt(field TimeField) Predicate
- func (f TimeField) LtTime(t time.Time) Predicate
- func (f TimeField) Ne(field TimeField) Predicate
- func (f TimeField) NeTime(t time.Time) Predicate
- func (f TimeField) NotBetween(start, end TimeField) Predicate
- func (f TimeField) NotBetweenTime(start, end time.Time) Predicate
- func (f TimeField) Set(value interface{}) FieldAssignment
- func (f TimeField) SetTime(value time.Time) FieldAssignment
- func (f TimeField) String() string
- type UpdateQuery
- func (q UpdateQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (q UpdateQuery) As(alias string) UpdateQuery
- func (q UpdateQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) UpdateQuery
- func (q UpdateQuery) Exec(db DB, flag ExecFlag) (rowsAffected int64, err error)
- func (q UpdateQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (rowsAffected int64, err error)
- func (q UpdateQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
- func (q UpdateQuery) Join(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
- func (q UpdateQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
- func (q UpdateQuery) Limit(limit int) UpdateQuery
- func (q UpdateQuery) NestThis() Query
- func (q UpdateQuery) OrderBy(fields ...Field) UpdateQuery
- func (q UpdateQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
- func (q UpdateQuery) Set(assignments ...Assignment) UpdateQuery
- func (q UpdateQuery) Setx(mapper func(*Column)) UpdateQuery
- func (q UpdateQuery) ToSQL() (query string, args []interface{})
- func (q UpdateQuery) Update(table BaseTable) UpdateQuery
- func (q UpdateQuery) Where(predicates ...Predicate) UpdateQuery
- func (q UpdateQuery) With(ctes ...CTE) UpdateQuery
- type VariadicPredicate
- type VariadicPredicateOperator
- type VariadicQuery
- func (vq VariadicQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (vq VariadicQuery) CTE(name string, columns ...string) CTE
- func (vq VariadicQuery) NestThis() Query
- func (vq VariadicQuery) Subquery(name string) Subquery
- func (vq VariadicQuery) ToSQL() (string, []interface{})
- type VariadicQueryOperator
- type Window
- func (w Window) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
- func (w Window) As(name string) Window
- func (w Window) Frame(frameDefinition string) Window
- func (w Window) Name() Window
- func (w Window) OrderBy(fields ...Field) Window
- func (w Window) PartitionBy(fields ...Field) Window
- type Windows
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assignment ¶
type Assignment interface { AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string) AssertAssignment() }
Assignment is an interface representing an SQL Assignment 'Field = Value'.
type Assignments ¶
type Assignments []Assignment
Assignments is a list of Assignments.
func (Assignments) AppendSQLExclude ¶
func (assignments Assignments) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the Assignments into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
type BaseQuery ¶
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 WithDefaultLog ¶
WithDefaultLog creates a new BaseQuery with the default logger and the LogFlag
func (BaseQuery) DeleteFrom ¶
func (q BaseQuery) DeleteFrom(tables ...BaseTable) DeleteQuery
DeleteFrom transforms the BaseQuery into a DeleteQuery.
func (BaseQuery) From ¶
func (q BaseQuery) From(table Table) SelectQuery
From transforms the BaseQuery into a SelectQuery.
func (BaseQuery) InsertIgnoreInto ¶
func (q BaseQuery) InsertIgnoreInto(table BaseTable) InsertQuery
InsertIgnoreInto transforms the BaseQuery into an InsertQuery.
func (BaseQuery) InsertInto ¶
func (q BaseQuery) InsertInto(table BaseTable) InsertQuery
InsertInto transforms the BaseQuery into an InsertQuery.
func (BaseQuery) Select ¶
func (q BaseQuery) Select(fields ...Field) SelectQuery
Select transforms the BaseQuery into a SelectQuery.
func (BaseQuery) SelectAll ¶
func (q BaseQuery) SelectAll() SelectQuery
SelectAll transforms the BaseQuery into a SelectQuery.
func (BaseQuery) SelectCount ¶
func (q BaseQuery) SelectCount() SelectQuery
SelectCount transforms the BaseQuery into a SelectQuery.
func (BaseQuery) SelectDistinct ¶
func (q BaseQuery) SelectDistinct(fields ...Field) SelectQuery
SelectDistinct transforms the BaseQuery into a SelectQuery.
func (BaseQuery) SelectOne ¶
func (q BaseQuery) SelectOne() SelectQuery
SelectOne transforms the BaseQuery into a SelectQuery.
func (BaseQuery) SelectRowx ¶
func (q BaseQuery) SelectRowx(mapper func(*Row)) SelectQuery
SelectRowx transforms the BaseQuery into a SelectQuery.
func (BaseQuery) Selectx ¶
func (q BaseQuery) Selectx(mapper func(*Row), accumulator func()) SelectQuery
Selectx transforms the BaseQuery into a SelectQuery.
func (BaseQuery) Union ¶ added in v0.2.0
func (q BaseQuery) Union(queries ...Query) VariadicQuery
Union transforms the BaseQuery into a VariadicQuery.
func (BaseQuery) UnionAll ¶ added in v0.2.0
func (q BaseQuery) UnionAll(queries ...Query) VariadicQuery
UnionAll transforms the BaseQuery into a VariadicQuery.
func (BaseQuery) Update ¶
func (q BaseQuery) Update(table BaseTable) UpdateQuery
Update transforms the BaseQuery into an UpdateQuery.
func (BaseQuery) WithDefaultLog ¶
WithDefaultLog adds the default logger and the LogFlag to the BaseQuery.
type BaseTable ¶
type BaseTable interface { Table AssertBaseTable() }
BaseTable is an interface that specialises the Table interface. It covers only tables/views that exist in the database.
type BinaryField ¶
type BinaryField struct {
// contains filtered or unexported fields
}
BinaryField either represents a BLOB column or a literal []byte value.
func Bytes ¶
func Bytes(b []byte) BinaryField
Bytes returns a new BinaryField representing a literal []byte value.
func NewBinaryField ¶
func NewBinaryField(name string, table Table) BinaryField
NewBinaryField returns a new BinaryField representing a BLOB column.
func (BinaryField) AppendSQLExclude ¶
func (f BinaryField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the BinaryField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.
func (BinaryField) GetAlias ¶
func (f BinaryField) GetAlias() string
GetAlias returns the alias of the BinaryField.
func (BinaryField) GetName ¶
func (f BinaryField) GetName() string
GetName returns the name of the BinaryField.
func (BinaryField) IsNotNull ¶
func (f BinaryField) IsNotNull() Predicate
IsNotNull returns an 'X IS NOT NULL' Predicate.
func (BinaryField) IsNull ¶
func (f BinaryField) IsNull() Predicate
IsNull returns an 'X IS NULL' Predicate.
func (BinaryField) Set ¶
func (f BinaryField) Set(v interface{}) FieldAssignment
Set returns a FieldAssignment associating the BinaryField to the value i.e. 'field = value'.
func (BinaryField) SetBytes ¶
func (f BinaryField) SetBytes(b []byte) FieldAssignment
SetBytes returns a FieldAssignment associating the BinaryField to the int value i.e. 'field = value'.
type BooleanField ¶
type BooleanField struct {
// contains filtered or unexported fields
}
BooleanField either represents a boolean column or a literal bool value.
func Bool ¶
func Bool(b bool) BooleanField
Bool returns a new Boolean Field representing a literal bool value.
func NewBooleanField ¶
func NewBooleanField(name string, table Table) BooleanField
NewBooleanField returns a new BooleanField representing a boolean column.
func (BooleanField) AppendSQLExclude ¶
func (f BooleanField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the BooleanField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.
func (BooleanField) As ¶
func (f BooleanField) As(alias string) BooleanField
As aliases the BooleanField i.e. 'field AS Alias'.
func (BooleanField) Asc ¶
func (f BooleanField) Asc() BooleanField
Asc returns a new BooleanField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.
func (BooleanField) Desc ¶
func (f BooleanField) Desc() BooleanField
Desc returns a new BooleanField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.
func (BooleanField) Eq ¶
func (f BooleanField) Eq(field BooleanField) Predicate
Eq returns an 'X = Y' Predicate. It only accepts BooleanField.
func (BooleanField) GetAlias ¶
func (f BooleanField) GetAlias() string
GetAlias returns the alias of the BooleanField.
func (BooleanField) GetName ¶
func (f BooleanField) GetName() string
GetName returns the name of the BooleanField.
func (BooleanField) IsNotNull ¶
func (f BooleanField) IsNotNull() Predicate
IsNotNull returns an 'X IS NOT NULL' Predicate.
func (BooleanField) IsNull ¶
func (f BooleanField) IsNull() Predicate
IsNull returns an 'X IS NULL' Predicate.
func (BooleanField) Ne ¶
func (f BooleanField) Ne(field BooleanField) Predicate
Ne returns an 'X <> Y' Predicate. It only accepts BooleanField.
func (BooleanField) Not ¶
func (f BooleanField) Not() Predicate
Not inverts the BooleanField i.e. 'NOT BooleanField'.
func (BooleanField) Set ¶
func (f BooleanField) Set(val interface{}) FieldAssignment
Set returns a FieldAssignment associating the BooleanField to the value i.e. 'field = value'.
func (BooleanField) SetBool ¶
func (f BooleanField) SetBool(val bool) FieldAssignment
SetBool returns a FieldAssignment associating the BooleanField to the bool value i.e. 'field = value'.
func (BooleanField) String ¶
func (f BooleanField) String() string
String returns the string representation of the BooleanField.
type CTE ¶
type CTE map[string]CustomField
CTE represents an SQL CTE.
func RecursiveCTE ¶ added in v0.2.0
RecursiveCTE constructs a new recursive CTE.
func (CTE) GetColumns ¶ added in v0.2.0
GetColumns returns the CTE's columns.
func (*CTE) Initial ¶ added in v0.2.0
func (cte *CTE) Initial(query Query) IntermediateCTE
Initial specifies recursive CTE's initial query. If the CTE is not recursive, this operation is a no-op.
func (CTE) IsRecursive ¶ added in v0.2.0
IsRecursive checks if the CTE is recursive.
type Column ¶ added in v0.4.0
type Column struct {
// contains filtered or unexported fields
}
Column keeps track of what the values mapped to what Field in an InsertQuery/SelectQuery.
func (*Column) SetBool ¶ added in v0.4.0
func (col *Column) SetBool(field BooleanField, value bool)
SetBool maps the bool value to the BooleanField.
func (*Column) SetFloat64 ¶ added in v0.4.0
func (col *Column) SetFloat64(field NumberField, value float64)
SetFloat64 maps the float64 value to the NumberField.
func (*Column) SetInt ¶ added in v0.4.0
func (col *Column) SetInt(field NumberField, value int)
SetInt maps the int value to the NumberField.
func (*Column) SetInt64 ¶ added in v0.4.0
func (col *Column) SetInt64(field NumberField, value int64)
SetInt64 maps the int64 value to the NumberField.
func (*Column) SetString ¶ added in v0.4.0
func (col *Column) SetString(field StringField, value string)
SetString maps the string value to the StringField.
type CustomAssignment ¶
type CustomAssignment struct { Format string Values []interface{} }
CustomAssignment is an Assignment that can render itself in an arbitrary way by calling expandValues on its Format and Values.
func (CustomAssignment) AppendSQLExclude ¶
func (set CustomAssignment) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the CustomAssignment into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (CustomAssignment) AssertAssignment ¶
func (set CustomAssignment) AssertAssignment()
AssertAssignment implements the Assignment interface.
type CustomField ¶
CustomField is a Field that can render itself in an arbitrary way by calling expandValues on its Format and Values.
func Fieldf ¶
func Fieldf(format string, values ...interface{}) CustomField
Fieldf creates a new CustomField.
func FirstValueOver ¶
func FirstValueOver(field interface{}, window Window) CustomField
FirstValueOver represents the FIRST_VALUE(field) OVER window function.
func LagOver ¶
func LagOver(field interface{}, offset interface{}, fallback interface{}, window Window) CustomField
LagOver represents the LAG(field, offset, fallback) OVER window function.
func LastValueOver ¶
func LastValueOver(field interface{}, window Window) CustomField
LastValueOver represents the LAST_VALUE(field) OVER window function.
func LeadOver ¶
func LeadOver(field interface{}, offset interface{}, fallback interface{}, window Window) CustomField
LeadOver represents the LEAD(field, offset, fallback) OVER window function.
func NthValueOver ¶
func NthValueOver(field interface{}, n int, window Window) CustomField
NthValueOver represents the NTH_VALUE(field, n) OVER window function.
func Values ¶
func Values(field Field) CustomField
Values wraps a field to simulate the VALUES(field) MySQL construct for the ON DUPLICATE KEY UPDATE clause.
func (CustomField) AppendSQLExclude ¶
func (f CustomField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the CustomField into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (CustomField) As ¶
func (f CustomField) As(alias string) CustomField
As aliases the CustomField i.e. 'field AS Alias'.
func (CustomField) Asc ¶
func (f CustomField) Asc() CustomField
Asc returns a new CustomField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.
func (CustomField) Desc ¶
func (f CustomField) Desc() CustomField
Desc returns a new CustomField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.
func (CustomField) Eq ¶
func (f CustomField) Eq(v interface{}) Predicate
Eq returns an 'X = Y' Predicate.
func (CustomField) Ge ¶
func (f CustomField) Ge(v interface{}) Predicate
Ge returns an 'X >= Y' Predicate.
func (CustomField) GetAlias ¶
func (f CustomField) GetAlias() string
GetAlias returns the alias of the CustomField.
func (CustomField) GetName ¶
func (f CustomField) GetName() string
GetName returns the name of the CustomField.
func (CustomField) Gt ¶
func (f CustomField) Gt(v interface{}) Predicate
Gt returns an 'X > Y' Predicate.
func (CustomField) In ¶
func (f CustomField) In(v interface{}) Predicate
In returns an 'X IN (Y)' Predicate.
func (CustomField) IsNotNull ¶
func (f CustomField) IsNotNull() Predicate
IsNotNull returns an 'X IS NOT NULL' Predicate.
func (CustomField) IsNull ¶
func (f CustomField) IsNull() Predicate
IsNull returns an 'X IS NULL' Predicate.
func (CustomField) Le ¶
func (f CustomField) Le(v interface{}) Predicate
Le returns an 'X <= Y' Predicate.
func (CustomField) Lt ¶
func (f CustomField) Lt(v interface{}) Predicate
Lt returns an 'X < Y' Predicate.
func (CustomField) Ne ¶
func (f CustomField) Ne(v interface{}) Predicate
Ne returns an 'X <> Y' Predicate.
func (CustomField) String ¶
func (f CustomField) String() string
String returns the string representation of the CustomField.
type CustomPredicate ¶
CustomPredicate is a Query that can render itself in an arbitrary way by calling expandValues on its Format and Values.
func Predicatef ¶
func Predicatef(format string, values ...interface{}) CustomPredicate
Predicatef creates a new CustomPredicate.
func (CustomPredicate) AppendSQLExclude ¶
func (p CustomPredicate) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the CustomPredicate into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (CustomPredicate) As ¶
func (p CustomPredicate) As(alias string) CustomPredicate
As aliases the CustomPredicate.
func (CustomPredicate) GetAlias ¶
func (p CustomPredicate) GetAlias() string
GetAlias returns the alias of the CustomPredicate.
func (CustomPredicate) GetName ¶
func (p CustomPredicate) GetName() string
GetName returns the name of the CustomPredicate, which is always an empty string.
func (CustomPredicate) Not ¶
func (p CustomPredicate) Not() Predicate
Not inverts the CustomPredicate i.e. 'NOT CustomPredicate'.
type DB ¶
type DB interface { Query(query string, args ...interface{}) (*sql.Rows, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) Exec(query string, args ...interface{}) (sql.Result, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) }
DB is an interface providing database querying abilities.
type DeleteQuery ¶
type DeleteQuery struct { Alias string // WITH CTEs []CTE // DELETE FROM FromTables []BaseTable // USING UsingTable Table JoinTables JoinTables // WHERE WherePredicate VariadicPredicate // ORDER BY OrderByFields Fields // LIMIT LimitValue *int64 // DB DB DB // Logging Log Logger LogFlag LogFlag // contains filtered or unexported fields }
DeleteQuery represents a DELETE query.
func DeleteFrom ¶
func DeleteFrom(tables ...BaseTable) DeleteQuery
DeleteFrom creates a new DeleteQuery.
func (DeleteQuery) AppendSQL ¶
func (q DeleteQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
AppendSQL marshals the DeleteQuery into a buffer and args slice.
func (DeleteQuery) CustomJoin ¶
func (q DeleteQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) DeleteQuery
CustomJoin custom joins a table to the DeleteQuery. The join type can be specified with a string, e.g. "CROSS JOIN".
func (DeleteQuery) DeleteFrom ¶
func (q DeleteQuery) DeleteFrom(tables ...BaseTable) DeleteQuery
DeleteFrom adds new tables to delete from to the DeleteQuery.
func (DeleteQuery) Exec ¶
func (q DeleteQuery) Exec(db DB, flag ExecFlag) (rowsAffected int64, err error)
Exec will execute the DeleteQuery with the given DB. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.
func (DeleteQuery) ExecContext ¶
func (q DeleteQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (rowsAffected int64, err error)
ExecContext will execute the DeleteQuery with the given DB and context. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.
func (DeleteQuery) FullJoin ¶
func (q DeleteQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
FullJoin full joins a table to the DeleteQuery based on the predicates.
func (DeleteQuery) Join ¶
func (q DeleteQuery) Join(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
Join joins a new table to the DeleteQuery based on the predicates.
func (DeleteQuery) LeftJoin ¶
func (q DeleteQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
LeftJoin left joins a new table to the DeleteQuery based on the predicates.
func (DeleteQuery) Limit ¶
func (q DeleteQuery) Limit(limit int) DeleteQuery
Limit sets the limit in the DeleteQuery.
func (DeleteQuery) NestThis ¶
func (q DeleteQuery) NestThis() Query
NestThis indicates to the DeleteQuery that it is nested.
func (DeleteQuery) OrderBy ¶
func (q DeleteQuery) OrderBy(fields ...Field) DeleteQuery
OrderBy appends the fields to the ORDER BY clause in the DeleteQuery.
func (DeleteQuery) RightJoin ¶
func (q DeleteQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) DeleteQuery
RightJoin right joins a new table to the DeleteQuery based on the predicates.
func (DeleteQuery) ToSQL ¶
func (q DeleteQuery) ToSQL() (string, []interface{})
ToSQL marshals the DeleteQuery into a query string and args slice.
func (DeleteQuery) Using ¶
func (q DeleteQuery) Using(table Table) DeleteQuery
Using adds a new table to the DeleteQuery.
func (DeleteQuery) Where ¶
func (q DeleteQuery) Where(predicates ...Predicate) DeleteQuery
Where appends the predicates to the WHERE clause in the DeleteQuery.
func (DeleteQuery) With ¶
func (q DeleteQuery) With(ctes ...CTE) DeleteQuery
With appends the CTEs into the DeleteQuery.
type EnumField ¶
type EnumField = StringField
EnumField is a type alias for StringField.
func NewEnumField ¶
NewEnumField returns an EnumField representing an enum column.
type ExitCode ¶
type ExitCode int
ExitCode represents a reason for terminating the rows.Next() loop.
type Field ¶
type Field interface { // Fields should respect the excludedTableQualifiers argument in ToSQL(). // E.g. if the field 'name' belongs to a table called 'users' and the // excludedTableQualifiers contains 'users', the field should present itself // as 'name' and not 'users.name'. i.e. any table qualifiers in the list // must be excluded. // // This is to play nice with certain clauses in the INSERT and UPDATE // queries that expressly forbid table qualified columns. AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string) GetAlias() string GetName() string }
Field is an interface that represents either a Table column or an SQL value.
type FieldAssignment ¶
type FieldAssignment struct { Field Field Value interface{} }
FieldAssignment represents a Field and Value set. Its usage appears in both the UPDATE and INSERT queries whenever values are assigned to columns e.g. 'field = value'.
func (FieldAssignment) AppendSQLExclude ¶
func (set FieldAssignment) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the FieldAssignment into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (FieldAssignment) AssertAssignment ¶
func (set FieldAssignment) AssertAssignment()
AssertAssignment implements the Assignment interface.
type FieldLiteral ¶
type FieldLiteral string
FieldLiteral is a Field where its underlying string is literally plugged into the SQL query.
func (FieldLiteral) AppendSQLExclude ¶
func (f FieldLiteral) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the FieldLiteral into a buffer and an args slice.
func (FieldLiteral) GetAlias ¶
func (f FieldLiteral) GetAlias() string
GetAlias returns the alias of the FieldLiteral, which is always an empty string.
func (FieldLiteral) GetName ¶
func (f FieldLiteral) GetName() string
GetName returns the FieldLiteral's underlying string.
type Fields ¶
type Fields []Field
Fields represents the "field1, field2, etc..." SQL construct.
func (Fields) AppendSQLExclude ¶
func (fs Fields) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals PredicateCases into a buffer and an args slice. It propagates the excludedTableQualifiers down to its Fields.
func (Fields) AppendSQLExcludeWithAlias ¶
func (fs Fields) AppendSQLExcludeWithAlias(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExcludeWithAlias is exactly like AppendSQLExclude, but appends each field (i.e. field1 AS alias1, field2 AS alias2, ...) with its alias if it has one.
type InsertQuery ¶
type InsertQuery struct { Alias string // INSERT INTO Ignore bool IntoTable BaseTable InsertColumns Fields // VALUES RowValues RowValues // SELECT SelectQuery *SelectQuery // ON DUPLICATE KEY Resolution Assignments // DB DB DB ColumnMapper func(*Column) // Logging Log Logger LogFlag LogFlag // contains filtered or unexported fields }
InsertQuery represents an INSERT query.
func InsertIgnoreInto ¶
func InsertIgnoreInto(table BaseTable) InsertQuery
InsertIgnoreInto creates a new InsertQuery.
func InsertInto ¶
func InsertInto(table BaseTable) InsertQuery
InsertInto creates a new InsertQuery.
func (InsertQuery) AppendSQL ¶
func (q InsertQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
AppendSQL marshals the InsertQuery into a buffer and args slice. Do not call this as an end user, use ToSQL instead. AppendSQL may panic if you wrote panic code in your ColumnMapper, it is only exported to satisfy the Query interface.
func (InsertQuery) Columns ¶
func (q InsertQuery) Columns(fields ...Field) InsertQuery
Columns sets the insert columns for the InsertQuery.
func (InsertQuery) Exec ¶
func (q InsertQuery) Exec(db DB, flag ExecFlag) (lastInsertID, rowsAffected int64, err error)
Exec will execute the InsertQuery with the given DB. It will only compute the lastInsertID if the ElastInsertID ExecFlag is passed to it. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it. To compute both, bitwise or the flags together i.e. ElastInsertID|ErowsAffected.
func (InsertQuery) ExecContext ¶
func (q InsertQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (lastInsertID, rowsAffected int64, err error)
ExecContext will execute the InsertQuery with the given DB and context. It will only compute the lastInsertID if the ElastInsertID ExecFlag is passed to it. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it. To compute both, bitwise or the flags together i.e. ElastInsertID|ErowsAffected.
func (InsertQuery) InsertIgnoreInto ¶
func (q InsertQuery) InsertIgnoreInto(table BaseTable) InsertQuery
InsertIgnoreInto sets the insert table for the InsertQuery.
func (InsertQuery) InsertInto ¶
func (q InsertQuery) InsertInto(table BaseTable) InsertQuery
InsertInto sets the insert table for the InsertQuery.
func (InsertQuery) NestThis ¶
func (q InsertQuery) NestThis() Query
NestThis indicates to the InsertQuery that it is nested.
func (InsertQuery) OnDuplicateKeyUpdate ¶
func (q InsertQuery) OnDuplicateKeyUpdate(assignments ...Assignment) InsertQuery
OnDuplicateKeyUpdate sets the assignments done on duplicate key for the InsertQuery.
func (InsertQuery) Select ¶
func (q InsertQuery) Select(selectQuery SelectQuery) InsertQuery
Select adds a SelectQuery to the InsertQuery.
func (InsertQuery) ToSQL ¶
func (q InsertQuery) ToSQL() (query string, args []interface{})
ToSQL marshals the InsertQuery into a query string and args slice.
func (InsertQuery) Values ¶
func (q InsertQuery) Values(values ...interface{}) InsertQuery
Values appends a new RowValue to the InsertQuery.
func (InsertQuery) Valuesx ¶ added in v0.4.0
func (q InsertQuery) Valuesx(mapper func(*Column)) InsertQuery
Valuesx sets the column mapper for the InsertQuery.
type IntermediateCTE ¶ added in v0.2.3
type IntermediateCTE map[string]CustomField
IntermediateCTE is a CTE used to hold the intermediate state of a recursive CTE just after the CTE's initial query is declared. It can only be converted back into a CTE by adding the recursive queries that UNION into the CTE.
func (IntermediateCTE) Union ¶ added in v0.2.3
func (cte IntermediateCTE) Union(queries ...Query) CTE
Union specifies the queries to be UNIONed into the CTE. If the CTE is not recursive, this operation is a no-op.
func (IntermediateCTE) UnionAll ¶ added in v0.2.3
func (cte IntermediateCTE) UnionAll(queries ...Query) CTE
UnionAll specifies the queries to be UNION-ALLed into the CTE. If the CTE is not recursive, this operation is a no-op.
type JSONField ¶
type JSONField struct {
// contains filtered or unexported fields
}
JSONField either represents a JSON column or a literal value that can be marshalled into a JSON string.
func JSON ¶
JSON returns a new JSONField representing a literal JSONable value. It returns an error indicating if the value can be marshalled into JSON.
func MustJSON ¶
func MustJSON(val interface{}) JSONField
MustJSON is like JSON but it panics on error.
func NewJSONField ¶
NewJSONField returns a new JSONField representing a JSON column.
func (JSONField) AppendSQLExclude ¶
func (f JSONField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the JSONField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.
func (JSONField) Asc ¶
Asc returns a new JSONField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.
func (JSONField) Desc ¶
Desc returns a new JSONField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.
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.
type JoinTable ¶
type JoinTable struct { JoinType JoinType Table Table OnPredicates VariadicPredicate }
JoinTable represents an SQL join.
func CustomJoin ¶
CustomJoin creates a custom join. The join type can be specified with a string, e.g. "CROSS JOIN".
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 AvgOver ¶
func AvgOver(field interface{}, window Window) NumberField
AvgOver represents the AVG() OVER window 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 MaxOver ¶
func MaxOver(field interface{}, window Window) NumberField
MaxOver represents the MAX() OVER window 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 SumOver ¶
func SumOver(field interface{}, window Window) NumberField
SumOver represents the SUM() OVER window function.
func (NumberField) AppendSQLExclude ¶
func (f NumberField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the NumberField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.
func (NumberField) As ¶
func (f NumberField) As(alias string) NumberField
As aliases the NumberField i.e. 'field AS Alias'.
func (NumberField) Asc ¶
func (f NumberField) Asc() NumberField
Asc returns a new NumberField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.
func (NumberField) Desc ¶
func (f NumberField) Desc() NumberField
Desc returns a new NumberField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.
func (NumberField) Eq ¶
func (f NumberField) Eq(field NumberField) Predicate
Eq returns an 'X = Y' Predicate. It only accepts NumberField.
func (NumberField) EqFloat64 ¶
func (f NumberField) EqFloat64(num float64) Predicate
EqFloat64 returns an 'X = Y' Predicate. It only accepts float64.
func (NumberField) EqInt ¶
func (f NumberField) EqInt(num int) Predicate
EqInt returns an 'X = Y' Predicate. It only accepts int.
func (NumberField) Ge ¶
func (f NumberField) Ge(field NumberField) Predicate
Ge returns an 'X >= Y' Predicate. It only accepts NumberField.
func (NumberField) GeFloat64 ¶
func (f NumberField) GeFloat64(num float64) Predicate
GeFloat64 returns an 'X >= Y' Predicate. It only accepts float64.
func (NumberField) GeInt ¶
func (f NumberField) GeInt(num int) Predicate
GeInt returns an 'X >= Y' Predicate. It only accepts int.
func (NumberField) GetAlias ¶
func (f NumberField) GetAlias() string
GetAlias returns the alias of the NumberField.
func (NumberField) GetName ¶
func (f NumberField) GetName() string
GetName returns the name of the NumberField.
func (NumberField) Gt ¶
func (f NumberField) Gt(field NumberField) Predicate
Gt returns an 'X > Y' Predicate. It only accepts NumberField.
func (NumberField) GtFloat64 ¶
func (f NumberField) GtFloat64(num float64) Predicate
GtFloat64 returns an 'X > Y' Predicate. It only accepts float64.
func (NumberField) GtInt ¶
func (f NumberField) GtInt(num int) Predicate
GtInt returns an 'X > Y' Predicate. It only accepts int.
func (NumberField) In ¶
func (f NumberField) In(v interface{}) Predicate
In returns an 'X IN (Y)' Predicate.
func (NumberField) IsNotNull ¶
func (f NumberField) IsNotNull() Predicate
IsNotNull returns an 'X IS NOT NULL' Predicate.
func (NumberField) IsNull ¶
func (f NumberField) IsNull() Predicate
IsNull returns an 'X IS NULL' Predicate.
func (NumberField) Le ¶
func (f NumberField) Le(field NumberField) Predicate
Le returns an 'X <= Y' Predicate. It only accepts NumberField.
func (NumberField) LeFloat64 ¶
func (f NumberField) LeFloat64(num float64) Predicate
LeFloat64 returns an 'X <= Y' Predicate. It only accepts float64.
func (NumberField) LeInt ¶
func (f NumberField) LeInt(num int) Predicate
LeInt returns an 'X <= Y' Predicate. It only accepts int.
func (NumberField) Lt ¶
func (f NumberField) Lt(field NumberField) Predicate
Lt returns an 'X < Y' Predicate. It only accepts NumberField.
func (NumberField) LtFloat64 ¶
func (f NumberField) LtFloat64(num float64) Predicate
LtFloat64 returns an 'X < Y' Predicate. It only accepts float64.
func (NumberField) LtInt ¶
func (f NumberField) LtInt(num int) Predicate
LtInt returns an 'X < Y' Predicate. It only accepts int.
func (NumberField) Ne ¶
func (f NumberField) Ne(field NumberField) Predicate
Ne returns an 'X <> Y' Predicate. It only accepts NumberField.
func (NumberField) NeFloat64 ¶
func (f NumberField) NeFloat64(num float64) Predicate
NeFloat64 returns an 'X <> Y' Predicate. It only accepts float64.
func (NumberField) NeInt ¶
func (f NumberField) NeInt(num int) Predicate
NeInt returns an 'X <> Y' Predicate. It only accepts int.
func (NumberField) Set ¶
func (f NumberField) Set(val interface{}) FieldAssignment
Set returns a FieldAssignment associating the NumberField to the value i.e. 'field = value'.
func (NumberField) SetFloat64 ¶
func (f NumberField) SetFloat64(num float64) FieldAssignment
SetFloat64 returns a FieldAssignment associating the NumberField to the float64 value i.e. 'field = value'.
func (NumberField) SetInt ¶
func (f NumberField) SetInt(num int) FieldAssignment
SetInt returns a FieldAssignment associating the NumberField to the int value i.e. 'field = value'.
func (NumberField) SetInt64 ¶
func (f NumberField) SetInt64(num int64) FieldAssignment
SetInt64 returns a FieldAssignment associating the NumberField to the int64 value i.e. 'field = value'.
func (NumberField) String ¶
func (f NumberField) String() string
String returns the string representation of the NumberField.
type PredicateCase ¶
type PredicateCase struct { Condition Predicate Result interface{} }
PredicateCase represents a Predicate and the Result if the Predicate is true.
type PredicateCases ¶
type PredicateCases struct { Alias string Cases []PredicateCase Fallback interface{} }
PredicateCases is the general form of the CASE expression.
func CaseWhen ¶
func CaseWhen(predicate Predicate, result interface{}) PredicateCases
CaseWhen creates a new PredicateCases i.e. CASE WHEN X THEN Y.
func (PredicateCases) AppendSQLExclude ¶
func (f PredicateCases) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the PredicateCases into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (PredicateCases) As ¶
func (f PredicateCases) As(alias string) PredicateCases
As aliases the PredicateCases.
func (PredicateCases) Else ¶
func (f PredicateCases) Else(fallback interface{}) PredicateCases
Else adds the fallback value for the PredicateCases i.e. ELSE X.
func (PredicateCases) GetAlias ¶
func (f PredicateCases) GetAlias() string
GetAlias returns the alias of the PredicateCases.
func (PredicateCases) GetName ¶
func (f PredicateCases) GetName() string
GetName returns the name of the PredicateCases, which is always an empty string.
func (PredicateCases) When ¶
func (f PredicateCases) When(predicate Predicate, result interface{}) PredicateCases
When adds a new PredicateCase to the PredicateCases i.e. WHEN X THEN Y.
type Query ¶
type Query interface { AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int) // When NestThis is called on a query, it signals to the query that it is // being nested as part of a larger query. The nested query should: // - hold off logging anything because the parent query will do it NestThis() Query ToSQL() (string, []interface{}) }
Query is an interface that specialises the Table interface. It covers only queries like SELECT/INSERT/UPDATE/DELETE.
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row represents the state of a row after a call to rows.Next().
func (*Row) Bool ¶
Bool returns the bool value of the Predicate. BooleanFields are considered predicates, so you can use them here.
func (*Row) BoolValid ¶
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) 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) 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.
type RowValue ¶
type RowValue []interface{}
RowValue represents an SQL Row Value Expression i.e. (a, b, c...)
func (RowValue) AppendSQLExclude ¶
func (r RowValue) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the RowValue into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (RowValue) In ¶
func (r RowValue) In(v interface{}) CustomPredicate
In returns an 'X IN (Y)' Predicate.
func (RowValue) Set ¶
func (r RowValue) Set(v interface{}) CustomAssignment
Set returns an Assignment assigning v to the RowValue.
type RowValues ¶
type RowValues []RowValue
RowValues represents a list of RowValues i.e. (a, b, c...), (d, e, f...), (g, h, i...)
type SelectQuery ¶
type SelectQuery struct { Alias string // WITH CTEs []CTE // SELECT SelectType SelectType SelectFields Fields // FROM FromTable Table JoinTables JoinTables // WHERE WherePredicate VariadicPredicate // GROUP BY GroupByFields Fields // HAVING HavingPredicate VariadicPredicate // WINDOW Windows Windows // ORDER BY OrderByFields Fields // LIMIT LimitValue *int64 // OFFSET OffsetValue *int64 // DB DB DB RowMapper func(*Row) Accumulator func() // Logging Log Logger LogFlag LogFlag // contains filtered or unexported fields }
SelectQuery represents a SELECT query.
func SelectDistinct ¶
func SelectDistinct(fields ...Field) SelectQuery
SelectDistinct creates a new SelectQuery.
func SelectRowx ¶
func SelectRowx(mapper func(*Row)) SelectQuery
SelectRowx creates a new SelectQuery.
func Selectx ¶
func Selectx(mapper func(*Row), accumulator func()) SelectQuery
Selectx creates a new SelectQuery.
func (SelectQuery) AppendSQL ¶
func (q SelectQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
AppendSQL marshals the SelectQuery into a buffer and args slice.
func (SelectQuery) CTE ¶ added in v0.2.0
func (q SelectQuery) CTE(name string, columns ...string) CTE
CTE converts a SelectQuery into a CTE.
func (SelectQuery) CustomJoin ¶
func (q SelectQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) SelectQuery
CustomJoin custom joins a table to the SelectQuery. The join type can be specified with a string, e.g. "CROSS JOIN".
func (SelectQuery) Fetch ¶
func (q SelectQuery) Fetch(db DB) (err error)
Fetch will run SelectQuery with the given DB. It then maps the results based on the mapper function (and optionally runs the accumulator function).
func (SelectQuery) FetchContext ¶
func (q SelectQuery) FetchContext(ctx context.Context, db DB) (err error)
FetchContext will run SelectQuery with the given DB and context. It then maps the results based on the mapper function (and optionally runs the accumulator function).
func (SelectQuery) From ¶
func (q SelectQuery) From(table Table) SelectQuery
From sets the table in the SelectQuery.
func (SelectQuery) FullJoin ¶
func (q SelectQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
FullJoin full joins a table to the SelectQuery based on the predicates.
func (SelectQuery) GroupBy ¶
func (q SelectQuery) GroupBy(fields ...Field) SelectQuery
GroupBy appends the fields to the GROUP BY clause in the SelectQuery.
func (SelectQuery) Having ¶
func (q SelectQuery) Having(predicates ...Predicate) SelectQuery
Having appends the predicates to the HAVING clause in the SelectQuery.
func (SelectQuery) Join ¶
func (q SelectQuery) Join(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
Join joins a new table to the SelectQuery based on the predicates.
func (SelectQuery) LeftJoin ¶
func (q SelectQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
LeftJoin left joins a new table to the SelectQuery based on the predicates.
func (SelectQuery) Limit ¶
func (q SelectQuery) Limit(limit int) SelectQuery
Limit sets the limit in the SelectQuery.
func (SelectQuery) NestThis ¶
func (q SelectQuery) NestThis() Query
NestThis indicates to the SelectQuery that it is nested.
func (SelectQuery) Offset ¶
func (q SelectQuery) Offset(offset int) SelectQuery
Offset sets the offset in the SelectQuery.
func (SelectQuery) OrderBy ¶
func (q SelectQuery) OrderBy(fields ...Field) SelectQuery
OrderBy appends the fields to the ORDER BY clause in the SelectQuery.
func (SelectQuery) RightJoin ¶
func (q SelectQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) SelectQuery
RightJoin right joins a new table to the SelectQuery based on the predicates.
func (SelectQuery) Select ¶
func (q SelectQuery) Select(fields ...Field) SelectQuery
Select adds the fields to the SelectFields in the SelectQuery.
func (SelectQuery) SelectAll ¶
func (q SelectQuery) SelectAll() SelectQuery
SelectAll sets the SELECT clause to SELECT *.
func (SelectQuery) SelectCount ¶
func (q SelectQuery) SelectCount() SelectQuery
SelectCount sets the SELECT clause to SELECT COUNT(*).
func (SelectQuery) SelectDistinct ¶
func (q SelectQuery) SelectDistinct(fields ...Field) SelectQuery
SelectDistinct adds the fields to the SelectFields in the SelectQuery.
func (SelectQuery) SelectOne ¶
func (q SelectQuery) SelectOne() SelectQuery
SelectOne sets the SELECT clause to SELECT 1.
func (SelectQuery) SelectRowx ¶
func (q SelectQuery) SelectRowx(mapper func(*Row)) SelectQuery
SelectRowx sets the mapper function in the SelectQuery.
func (SelectQuery) Selectx ¶
func (q SelectQuery) Selectx(mapper func(*Row), accumulator func()) SelectQuery
Selectx sets the mapper function and accumulator function in the SelectQuery.
func (SelectQuery) Subquery ¶ added in v0.2.0
func (q SelectQuery) Subquery(alias string) Subquery
Subquery converts a SelectQuery into a Subquery.
func (SelectQuery) ToSQL ¶
func (q SelectQuery) ToSQL() (string, []interface{})
ToSQL marshals the SelectQuery into a query string and args slice.
func (SelectQuery) Where ¶
func (q SelectQuery) Where(predicates ...Predicate) SelectQuery
Where appends the predicates to the WHERE clause in the SelectQuery.
func (SelectQuery) Window ¶
func (q SelectQuery) Window(windows ...Window) SelectQuery
Window appends the windows to the WINDOW clause in the SelectQuery.
func (SelectQuery) With ¶
func (q SelectQuery) With(ctes ...CTE) SelectQuery
With appends a list of CTEs into the SelectQuery.
type SelectType ¶
type SelectType string
SelectType represents the various SQL selects.
const ( SelectTypeDefault SelectType = "SELECT" SelectTypeDistinct SelectType = "SELECT DISTINCT" )
SelectTypes
type SimpleCase ¶
type SimpleCase struct { Value interface{} Result interface{} }
SimpleCase represents a Value to be compared against and the Result if it matches.
type SimpleCases ¶
type SimpleCases struct { Alias string Expression interface{} Cases []SimpleCase Fallback interface{} }
SimpleCases is the simple form of the CASE expression.
func (SimpleCases) AppendSQLExclude ¶
func (f SimpleCases) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the SimpleCases into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (SimpleCases) As ¶
func (f SimpleCases) As(alias string) SimpleCases
As aliases the SimpleCases.
func (SimpleCases) Else ¶
func (f SimpleCases) Else(field Field) SimpleCases
Else adds the fallback value for the SimpleCases i.e. ELSE X.
func (SimpleCases) GetAlias ¶
func (f SimpleCases) GetAlias() string
GetAlias returns the alias of the SimpleCases.
func (SimpleCases) GetName ¶
func (f SimpleCases) GetName() string
GetName returns the name of the simple cases, which is always an empty string.
func (SimpleCases) When ¶
func (f SimpleCases) When(field Field, result Field) SimpleCases
When adds a new SimpleCase to the SimpleCases i.e. WHEN X THEN Y.
type StringField ¶
type StringField struct {
// contains filtered or unexported fields
}
StringField either represents a string column or a literal string value.
func NewStringField ¶
func NewStringField(name string, table Table) StringField
NewStringField returns a new StringField representing a boolean column.
func String ¶
func String(s string) StringField
String returns a new StringField representing a literal string value.
func (StringField) AppendSQLExclude ¶
func (f StringField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the StringField into a buffer and an args slice. It will not table qualify itself if its table qualifer appears in the excludedTableQualifiers list.
func (StringField) As ¶
func (f StringField) As(alias string) StringField
As returns a new StringField with the new field Alias i.e. 'field AS Alias'.
func (StringField) Asc ¶
func (f StringField) Asc() StringField
Asc returns a new StringField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.
func (StringField) Desc ¶
func (f StringField) Desc() StringField
Desc returns a new StringField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.
func (StringField) Eq ¶
func (f StringField) Eq(field StringField) Predicate
Eq returns an 'X = Y' Predicate. It only accepts StringField.
func (StringField) EqString ¶
func (f StringField) EqString(s string) Predicate
EqString returns an 'X = Y' Predicate. It only accepts string.
func (StringField) Ge ¶
func (f StringField) Ge(field StringField) Predicate
Ge returns an 'X >= Y' Predicate. It only accepts StringField.
func (StringField) GeString ¶
func (f StringField) GeString(s string) Predicate
GeString returns an 'X >= Y' Predicate. It only accepts string.
func (StringField) GetAlias ¶
func (f StringField) GetAlias() string
GetAlias returns the alias of the StringField.
func (StringField) GetName ¶
func (f StringField) GetName() string
GetName returns the name of the StringField.
func (StringField) Gt ¶
func (f StringField) Gt(field StringField) Predicate
Gt returns an 'X > Y' Predicate. It only accepts StringField.
func (StringField) GtString ¶
func (f StringField) GtString(s string) Predicate
GtString returns an 'X > Y' Predicate. It only accepts string.
func (StringField) In ¶
func (f StringField) In(v interface{}) Predicate
In returns an 'X IN (Y)' Predicate.
func (StringField) IsNotNull ¶
func (f StringField) IsNotNull() Predicate
IsNotNull returns an 'X IS NOT NULL' Predicate.
func (StringField) IsNull ¶
func (f StringField) IsNull() Predicate
IsNull returns an 'X IS NULL' Predicate.
func (StringField) Le ¶
func (f StringField) Le(field StringField) Predicate
Le returns an 'X <= Y' Predicate. It only accepts StringField.
func (StringField) LeString ¶
func (f StringField) LeString(s string) Predicate
LeString returns an 'X <= Y' Predicate. It only accepts string.
func (StringField) LikeString ¶
func (f StringField) LikeString(s string) Predicate
LikeString returns an 'A LIKE B' Predicate. It only accepts string.
func (StringField) Lt ¶
func (f StringField) Lt(field StringField) Predicate
Lt returns an 'X < Y' Predicate. It only accepts StringField.
func (StringField) LtString ¶
func (f StringField) LtString(s string) Predicate
LtString returns an 'X < Y' Predicate. It only accepts string.
func (StringField) Ne ¶
func (f StringField) Ne(field StringField) Predicate
Ne returns an 'X <> Y' Predicate. It only accepts StringField.
func (StringField) NeString ¶
func (f StringField) NeString(s string) Predicate
NeString returns an 'X <> Y' Predicate. It only accepts string.
func (StringField) NotLikeString ¶
func (f StringField) NotLikeString(s string) Predicate
NotLikeString returns an 'A NOT LIKE B' Predicate. It only accepts string.
func (StringField) Set ¶
func (f StringField) Set(value interface{}) FieldAssignment
Set returns a FieldAssignment associating the StringField to the value i.e. 'field = value'.
func (StringField) SetString ¶
func (f StringField) SetString(s string) FieldAssignment
SetString returns a FieldAssignment associating the StringField to the string value i.e. 'field = value'.
func (StringField) String ¶
func (f StringField) String() string
String returns the string representation of the StringField.
type Subquery ¶ added in v0.2.0
type Subquery map[string]CustomField
Subquery represents an SQL subquery.
func (Subquery) AppendSQL ¶ added in v0.2.0
AppendSQL marshals the Subquery into a buffer and args slice.
type Table ¶
type Table interface { AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int) GetAlias() string GetName() string }
Table is an interface representing anything that you can SELECT FROM or JOIN.
type TableInfo ¶
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) AssertBaseTable ¶
func (tbl *TableInfo) AssertBaseTable()
AssertBaseTable implements the BaseTable interface.
type TimeField ¶
type TimeField struct {
// contains filtered or unexported fields
}
TimeField either represents a time column or a literal time.Time value.
func NewTimeField ¶
NewTimeField returns a new TimeField representing a time column.
func (TimeField) AppendSQLExclude ¶
func (f TimeField) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the TimeField into an SQL query and args as described in the TimeField internal struct comments.
func (TimeField) Asc ¶
Asc returns a new TimeField indicating that it should be ordered in ascending order i.e. 'ORDER BY field ASC'.
func (TimeField) Between ¶
Between returns an 'X BETWEEN Y AND Z' Predicate. It only accepts TimeField.
func (TimeField) BetweenTime ¶
BetweenTime returns an 'X BETWEEN Y AND Z' Predicate. It only accepts time.Time.
func (TimeField) Desc ¶
Desc returns a new TimeField indicating that it should be ordered in descending order i.e. 'ORDER BY field DESC'.
func (TimeField) NotBetween ¶
NotBetween returns an 'X NOT BETWEEN Y AND Z' Predicate. It only accepts TimeField.
func (TimeField) NotBetweenTime ¶
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'.
type UpdateQuery ¶
type UpdateQuery struct { Alias string // WITH CTEs []CTE // UPDATE UpdateTable BaseTable // SET Assignments Assignments // JOIN JoinTables JoinTables // WHERE WherePredicate VariadicPredicate // ORDER BY OrderByFields Fields // LIMIT LimitValue *int64 // DB DB DB ColumnMapper func(*Column) // Logging Log Logger LogFlag LogFlag // contains filtered or unexported fields }
UpdateQuery represents an UPDATE query.
func (UpdateQuery) AppendSQL ¶
func (q UpdateQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
AppendSQL marshals the UpdateQuery into a buffer and args slice. Do not call this as an end user, use ToSQL instead. AppendSQL may panic if you wrote panic code in your ColumnMapper, it is only exported to satisfy the Query interface.
func (UpdateQuery) As ¶
func (q UpdateQuery) As(alias string) UpdateQuery
As aliases the UpdateQuery i.e. 'query AS alias'.
func (UpdateQuery) CustomJoin ¶
func (q UpdateQuery) CustomJoin(joinType JoinType, table Table, predicates ...Predicate) UpdateQuery
CustomJoin custom joins a table to the UpdateQuery. The join type can be specified with a string, e.g. "CROSS JOIN".
func (UpdateQuery) Exec ¶
func (q UpdateQuery) Exec(db DB, flag ExecFlag) (rowsAffected int64, err error)
Exec will execute the UpdateQuery with the given DB. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.
func (UpdateQuery) ExecContext ¶
func (q UpdateQuery) ExecContext(ctx context.Context, db DB, flag ExecFlag) (rowsAffected int64, err error)
ExecContext will execute the UpdateQuery with the given DB and context. It will only compute the rowsAffected if the ErowsAffected Execflag is passed to it.
func (UpdateQuery) FullJoin ¶
func (q UpdateQuery) FullJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
FullJoin full joins a table to the UpdateQuery based on the predicates.
func (UpdateQuery) Join ¶
func (q UpdateQuery) Join(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
Join joins a new table to the UpdateQuery based on the predicates.
func (UpdateQuery) LeftJoin ¶
func (q UpdateQuery) LeftJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
LeftJoin left joins a new table to the UpdateQuery based on the predicates.
func (UpdateQuery) Limit ¶
func (q UpdateQuery) Limit(limit int) UpdateQuery
Limit sets the limit in the UpdateQuery.
func (UpdateQuery) NestThis ¶
func (q UpdateQuery) NestThis() Query
NestThis indicates to the UpdateQuery that it is nested.
func (UpdateQuery) OrderBy ¶
func (q UpdateQuery) OrderBy(fields ...Field) UpdateQuery
OrderBy appends the fields to the ORDER BY clause in the UpdateQuery.
func (UpdateQuery) RightJoin ¶
func (q UpdateQuery) RightJoin(table Table, predicate Predicate, predicates ...Predicate) UpdateQuery
RightJoin right joins a new table to the UpdateQuery based on the predicates.
func (UpdateQuery) Set ¶
func (q UpdateQuery) Set(assignments ...Assignment) UpdateQuery
Set appends the assignments to SET clause of the UpdateQuery.
func (UpdateQuery) Setx ¶ added in v0.4.0
func (q UpdateQuery) Setx(mapper func(*Column)) UpdateQuery
Setx sets the column mapper function UpdateQuery.
func (UpdateQuery) ToSQL ¶
func (q UpdateQuery) ToSQL() (query string, args []interface{})
ToSQL marshals the UpdateQuery into a query string and args slice.
func (UpdateQuery) Update ¶
func (q UpdateQuery) Update(table BaseTable) UpdateQuery
Update sets the update table for the UpdateQuery.
func (UpdateQuery) Where ¶
func (q UpdateQuery) Where(predicates ...Predicate) UpdateQuery
Where appends the predicates to the WHERE clause in the UpdateQuery.
func (UpdateQuery) With ¶
func (q UpdateQuery) With(ctes ...CTE) UpdateQuery
With appends a list of CTEs into the UpdateQuery.
type VariadicPredicate ¶
type VariadicPredicate struct { Alias string Operator VariadicPredicateOperator Predicates []Predicate Negative bool // contains filtered or unexported fields }
VariadicPredicate represents the "x AND y AND z..." or "x OR y OR z..." SQL construct.
func And ¶
func And(predicates ...Predicate) VariadicPredicate
And joins the list of predicates together with the AND operator.
func Or ¶
func Or(predicates ...Predicate) VariadicPredicate
Or joins the list of predicates together with the OR operator.
func (VariadicPredicate) AppendSQLExclude ¶
func (p VariadicPredicate) AppendSQLExclude(buf *strings.Builder, args *[]interface{}, params map[string]int, excludedTableQualifiers []string)
AppendSQLExclude marshals the VariadicPredicate into a buffer and an args slice. It propagates the excludedTableQualifiers down to its child elements.
func (VariadicPredicate) GetAlias ¶
func (p VariadicPredicate) GetAlias() string
GetAlias returns the alias of the VariadicPredicate.
func (VariadicPredicate) GetName ¶
func (p VariadicPredicate) GetName() string
GetName returns the name of the VariadicPredicate, which is always an empty string.
func (VariadicPredicate) Not ¶
func (p VariadicPredicate) Not() Predicate
Not inverts the VariadicPredicate i.e. 'NOT VariadicPredicate'.
type VariadicPredicateOperator ¶
type VariadicPredicateOperator string
VariadicPredicateOperator is an operator that can join a variadic number of Predicates together.
const ( PredicateOr VariadicPredicateOperator = "OR" PredicateAnd VariadicPredicateOperator = "AND" )
VariadicPredicateOperators
type VariadicQuery ¶
type VariadicQuery struct { Operator VariadicQueryOperator Queries []Query // DB DB DB Mapper func(*Row) Accumulator func() // Logging Log Logger LogFlag LogFlag // contains filtered or unexported fields }
VariadicQuery represents a variadic number of queries joined together by an VariadicQueryOperator.
func Except ¶
func Except(queries ...Query) VariadicQuery
Except joins the list of queries together with the EXCEPT operator.
func ExceptAll ¶
func ExceptAll(queries ...Query) VariadicQuery
ExceptAll joins the list of queries together with the EXCEPT ALL operator.
func Intersect ¶
func Intersect(queries ...Query) VariadicQuery
Intersect joins the list of queries together with the INTERSECT operator.
func IntersectAll ¶
func IntersectAll(queries ...Query) VariadicQuery
IntersectAll joins the list of queries together with the INTERSECT ALL operator.
func Union ¶
func Union(queries ...Query) VariadicQuery
Union joins the list of queries together with the UNION operator.
func UnionAll ¶
func UnionAll(queries ...Query) VariadicQuery
UnionAll joins the list of queries together with the UNION ALL operator.
func (VariadicQuery) AppendSQL ¶
func (vq VariadicQuery) AppendSQL(buf *strings.Builder, args *[]interface{}, params map[string]int)
AppendSQL marshals the VariadicQuery into a buffer and args slice.
func (VariadicQuery) CTE ¶ added in v0.2.0
func (vq VariadicQuery) CTE(name string, columns ...string) CTE
CTE converts a VariadicQuery into a CTE.
func (VariadicQuery) NestThis ¶
func (vq VariadicQuery) NestThis() Query
NestThis indicates to the VariadicQuery that it is nested.
func (VariadicQuery) Subquery ¶ added in v0.2.0
func (vq VariadicQuery) Subquery(name string) Subquery
Subquery converts a VariadicQuery into a Subquery.
func (VariadicQuery) ToSQL ¶
func (vq VariadicQuery) ToSQL() (string, []interface{})
ToSQL marshals the VariadicQuery into a query string and args slice.
type VariadicQueryOperator ¶
type VariadicQueryOperator string
VariadicQueryOperator is an operator that can join a variadic number of queries together.
const ( QueryUnion VariadicQueryOperator = "UNION" QueryUnionAll VariadicQueryOperator = "UNION ALL" QueryIntersect VariadicQueryOperator = "INTERSECT" QueryIntersectAll VariadicQueryOperator = "INTERSECT ALL" QueryExcept VariadicQueryOperator = "EXCEPT" QueryExceptAll VariadicQueryOperator = "EXCEPT ALL" )
VariadicQueryOperators
type Window ¶
type Window struct { WindowName string PartitionByFields Fields OrderByFields Fields FrameDefinition string // contains filtered or unexported fields }
Window represents a window usable in a window function.
func (Window) Frame ¶
Frame sets the frame definition of the window e.g. RANGE BETWEEN 5 PRECEDING AND 10 FOLLOWING.
func (Window) PartitionBy ¶
PartitionBy sets the fields of the window's PARTITION BY clause.
Source Files ¶
- aggregate_functions.go
- base_query.go
- binary_field.go
- boolean_field.go
- case.go
- column.go
- cte.go
- custom_field.go
- delete_query.go
- fields.go
- insert_query.go
- join_table.go
- json_field.go
- number_field.go
- predicates.go
- row.go
- row_values.go
- select_query.go
- sq.go
- string_field.go
- string_util.go
- subquery.go
- table_info.go
- time_field.go
- update_query.go
- variadic_queries.go
- window.go