Documentation ¶
Overview ¶
Package stmt defines various statements and clauses that are used to generate queries.
Unless you have to develop complex queries, you should'nt have to use this package.
Index ¶
- Constants
- type Array
- type Between
- type BoolEncoder
- type Column
- type ComparisonOperator
- type ConflictAction
- type ConflictNoAction
- type ConflictTarget
- type ConflictUpdateAction
- type Count
- type Delete
- type Exists
- type Expression
- type From
- type GroupBy
- type Having
- type Identifier
- func (identifier Identifier) Between(from, to interface{}) Between
- func (identifier Identifier) Equal(value interface{}) InfixExpression
- func (identifier Identifier) GreaterThan(value interface{}) InfixExpression
- func (identifier Identifier) GreaterThanOrEqual(value interface{}) InfixExpression
- func (identifier Identifier) ILike(value interface{}) InfixExpression
- func (identifier Identifier) In(value ...interface{}) In
- func (identifier Identifier) Is(value interface{}) InfixExpression
- func (identifier Identifier) IsEmpty() bool
- func (identifier Identifier) IsNot(value interface{}) InfixExpression
- func (identifier Identifier) IsNull(value bool) InfixExpression
- func (identifier Identifier) LessThan(value interface{}) InfixExpression
- func (identifier Identifier) LessThanOrEqual(value interface{}) InfixExpression
- func (identifier Identifier) Like(value interface{}) InfixExpression
- func (identifier Identifier) NotBetween(from, to interface{}) Between
- func (identifier Identifier) NotEqual(value interface{}) InfixExpression
- func (identifier Identifier) NotILike(value interface{}) InfixExpression
- func (identifier Identifier) NotIn(value ...interface{}) In
- func (identifier Identifier) NotLike(value interface{}) InfixExpression
- func (identifier Identifier) Write(ctx types.Context)
- type In
- type InfixExpression
- type InfixOnExpression
- type Insert
- type Int64Encoder
- type Into
- type Join
- type Limit
- type LogicalOperator
- type Max
- type Min
- type Offset
- type OnClause
- type OnConflict
- type OnExpression
- type Operator
- type Order
- type OrderBy
- type PairContainer
- func (pairs *PairContainer) Add(column Column, expression Expression)
- func (pairs PairContainer) IsEmpty() bool
- func (pairs *PairContainer) Set(column Column)
- func (pairs *PairContainer) Use(expression Expression)
- func (pairs PairContainer) Values() ([]Column, []Expression)
- func (pairs PairContainer) Write(ctx types.Context)
- func (pairs PairContainer) WriteArray(ctx types.Context)
- func (pairs PairContainer) WriteAssociative(ctx types.Context)
- type PairMode
- type Prefix
- type Raw
- type Returning
- type Select
- type SelectExpression
- type Set
- type Statement
- type StatementEncoder
- type StringEncoder
- type Suffix
- type Sum
- type Table
- type TimeEncoder
- type Update
- type Using
- type Value
- type Values
- type Where
- type With
- type WithQuery
- type Wrapper
Constants ¶
const ( // PairUnknownMode define an unknown mode. PairUnknownMode = PairMode(iota) // PairAssociativeMode define a key-value mode for PairContainer. PairAssociativeMode // PairArrayMode define a column-list mode for PairContainer. PairArrayMode )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
Values []Expression
}
Array contains a list of expression values.
func (*Array) Append ¶
func (array *Array) Append(value interface{})
Append an expression to the given array.
type Between ¶
type Between struct { Identifier Identifier Operator ComparisonOperator From Expression And LogicalOperator To Expression }
Between is a BETWEEN expression.
func NewBetween ¶
func NewBetween(identifier Identifier, from, to Expression) Between
NewBetween returns a new Between instance using an inclusive operator.
func NewNotBetween ¶
func NewNotBetween(identifier Identifier, from, to Expression) Between
NewNotBetween returns a new Between instance using an exclusive operator.
type BoolEncoder ¶
type BoolEncoder interface {
Bool() bool
}
BoolEncoder can encode a value as a bool to creates a Value instance.
type Column ¶
Column is a column identifier.
func NewColumnAlias ¶
NewColumnAlias returns a new Column instance with an alias.
type ComparisonOperator ¶
type ComparisonOperator struct {
Operator types.ComparisonOperator
}
ComparisonOperator are used to evaluate two expressions using a comparison operator.
func NewComparisonOperator ¶
func NewComparisonOperator(operator types.ComparisonOperator) ComparisonOperator
NewComparisonOperator returns a new ComparisonOperator instance.
func (ComparisonOperator) IsEmpty ¶
func (operator ComparisonOperator) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (ComparisonOperator) Write ¶
func (operator ComparisonOperator) Write(ctx types.Context)
Write exposes statement as a SQL query.
type ConflictAction ¶
type ConflictAction interface { Statement // contains filtered or unexported methods }
ConflictAction is a action used by ON CONFLICT expression. It can be either DO NOTHING, or a DO UPDATE clause.
type ConflictNoAction ¶
type ConflictNoAction struct{}
ConflictNoAction is a DO NOTHING clause on ON CONFLICT expression.
func NewConflictNoAction ¶
func NewConflictNoAction() ConflictNoAction
NewConflictNoAction returns a new ConflictNoAction instance.
func (ConflictNoAction) IsEmpty ¶
func (ConflictNoAction) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (ConflictNoAction) Write ¶
func (ConflictNoAction) Write(ctx types.Context)
Write exposes statement as a SQL query.
type ConflictTarget ¶
type ConflictTarget struct {
Columns []Column
}
ConflictTarget is a column identifier.
func NewConflictTarget ¶
func NewConflictTarget(columns []Column) ConflictTarget
NewConflictTarget returns a new ConflictTarget instance.
func (ConflictTarget) IsEmpty ¶
func (target ConflictTarget) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (ConflictTarget) Write ¶
func (target ConflictTarget) Write(ctx types.Context)
Write exposes statement as a SQL query.
type ConflictUpdateAction ¶
type ConflictUpdateAction struct {
Set Set
}
ConflictUpdateAction is a DO UPDATE clause on ON CONFLICT expression.
func NewConflictUpdateAction ¶
func NewConflictUpdateAction(set Set) ConflictUpdateAction
NewConflictUpdateAction returns a new ConflictUpdateAction instance.
func (ConflictUpdateAction) IsEmpty ¶
func (action ConflictUpdateAction) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (ConflictUpdateAction) Write ¶
func (action ConflictUpdateAction) Write(ctx types.Context)
Write exposes statement as a SQL query.
type Count ¶
Count is a aggregate expression.
type Delete ¶
Delete is a DELETE statement.
type Exists ¶
type Exists struct {
Subquery Expression
}
Exists is a subquery expression.
type Expression ¶
type Expression interface { Statement // contains filtered or unexported methods }
Expression is a SQL expression.
func NewArrayExpression ¶
func NewArrayExpression(values ...interface{}) Expression
NewArrayExpression creates a new Expression using a list of values.
func NewExpression ¶
func NewExpression(arg interface{}) Expression
NewExpression returns a new Expression instance from arg.
func NewWrapper ¶
func NewWrapper(arg Expression) Expression
NewWrapper returns a new Wrapper expression when it's required.
type From ¶
From is a FROM clause.
type GroupBy ¶
type GroupBy struct {
Columns []Column
}
GroupBy is a GROUP BY clause.
func NewGroupBy ¶
NewGroupBy returns a new GroupBy instance.
type Having ¶
type Having struct { Statement Condition Expression }
Having is a HAVING clause.
func NewHaving ¶
func NewHaving(expression Expression) Having
NewHaving returns a new Having instance.
func (Having) And ¶
func (having Having) And(right Expression) Having
And appends given Expression using AND as logical operator.
func (Having) Or ¶
func (having Having) Or(right Expression) Having
Or appends given Expression using OR as logical operator.
type Identifier ¶
type Identifier struct {
Identifier string
}
Identifier is an identifier.
func NewIdentifier ¶
func NewIdentifier(identifier string) Identifier
NewIdentifier returns a new Identifier.
func (Identifier) Between ¶
func (identifier Identifier) Between(from, to interface{}) Between
Between performs a "between" condition.
func (Identifier) Equal ¶
func (identifier Identifier) Equal(value interface{}) InfixExpression
Equal performs an "equal" comparison.
func (Identifier) GreaterThan ¶
func (identifier Identifier) GreaterThan(value interface{}) InfixExpression
GreaterThan performs a "greater than" comparison.
func (Identifier) GreaterThanOrEqual ¶
func (identifier Identifier) GreaterThanOrEqual(value interface{}) InfixExpression
GreaterThanOrEqual performs a "greater than or equal to" comparison.
func (Identifier) ILike ¶
func (identifier Identifier) ILike(value interface{}) InfixExpression
ILike performs a "ilike" condition.
func (Identifier) In ¶
func (identifier Identifier) In(value ...interface{}) In
In performs a "in" condition.
func (Identifier) Is ¶
func (identifier Identifier) Is(value interface{}) InfixExpression
Is performs a "is" comparison.
func (Identifier) IsEmpty ¶
func (identifier Identifier) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (Identifier) IsNot ¶
func (identifier Identifier) IsNot(value interface{}) InfixExpression
IsNot performs a "is not" comparison.
func (Identifier) IsNull ¶
func (identifier Identifier) IsNull(value bool) InfixExpression
IsNull performs a "is null" comparison.
func (Identifier) LessThan ¶
func (identifier Identifier) LessThan(value interface{}) InfixExpression
LessThan performs a "less than" comparison.
func (Identifier) LessThanOrEqual ¶
func (identifier Identifier) LessThanOrEqual(value interface{}) InfixExpression
LessThanOrEqual performs a "less than or equal to" comparison.
func (Identifier) Like ¶
func (identifier Identifier) Like(value interface{}) InfixExpression
Like performs a "like" condition.
func (Identifier) NotBetween ¶
func (identifier Identifier) NotBetween(from, to interface{}) Between
NotBetween performs a "not between" condition.
func (Identifier) NotEqual ¶
func (identifier Identifier) NotEqual(value interface{}) InfixExpression
NotEqual performs a "not equal" comparison.
func (Identifier) NotILike ¶
func (identifier Identifier) NotILike(value interface{}) InfixExpression
NotILike performs a "not ilike" condition.
func (Identifier) NotIn ¶
func (identifier Identifier) NotIn(value ...interface{}) In
NotIn performs a "not in" condition.
func (Identifier) NotLike ¶
func (identifier Identifier) NotLike(value interface{}) InfixExpression
NotLike performs a "not like" condition.
func (Identifier) Write ¶
func (identifier Identifier) Write(ctx types.Context)
Write exposes statement as a SQL query.
type In ¶
type In struct { Identifier Identifier Operator ComparisonOperator Value Expression }
In is a IN expression.
func NewIn ¶
func NewIn(identifier Identifier, value Expression) In
NewIn returns a new In instance using an inclusive operator.
func NewNotIn ¶
func NewNotIn(identifier Identifier, value Expression) In
NewNotIn returns a new In instance using an exclusive operator.
func (In) And ¶
func (in In) And(value Expression) InfixExpression
And creates a new InfixExpression using given Expression.
func (In) Or ¶
func (in In) Or(value Expression) InfixExpression
Or creates a new InfixExpression using given Expression.
type InfixExpression ¶
type InfixExpression struct { Left Expression Operator Operator Right Expression }
InfixExpression is an Expression that has a left and right operand with an operator. For example, the expression 'id >= 30' is an infix expression.
func NewInfixExpression ¶
func NewInfixExpression(left Expression, operator Operator, right Expression) InfixExpression
NewInfixExpression returns a new InfixExpression instance.
func (InfixExpression) And ¶
func (expression InfixExpression) And(value Expression) InfixExpression
And creates a new InfixExpression using given Expression.
func (InfixExpression) IsEmpty ¶
func (expression InfixExpression) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (InfixExpression) Or ¶
func (expression InfixExpression) Or(value Expression) InfixExpression
Or creates a new InfixExpression using given Expression.
func (InfixExpression) Write ¶
func (expression InfixExpression) Write(ctx types.Context)
Write exposes statement as a SQL query.
type InfixOnExpression ¶
type InfixOnExpression struct { Left OnExpression Operator LogicalOperator Right OnExpression }
InfixOnExpression is an OnExpression that has a left and right clauses with a logical operator for an ON statement.
func NewInfixOnExpression ¶
func NewInfixOnExpression(left OnExpression, operator LogicalOperator, right OnExpression) InfixOnExpression
NewInfixOnExpression returns a new InfixOnExpression instance.
func (InfixOnExpression) And ¶
func (expression InfixOnExpression) And(value OnExpression) OnExpression
And creates a new InfixOnExpression using given OnExpression.
func (InfixOnExpression) IsEmpty ¶
func (expression InfixOnExpression) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (InfixOnExpression) Or ¶
func (expression InfixOnExpression) Or(value OnExpression) OnExpression
Or creates a new InfixOnExpression using given OnExpression.
func (InfixOnExpression) Write ¶
func (expression InfixOnExpression) Write(ctx types.Context)
Write exposes statement as a SQL query.
type Insert ¶
type Insert struct { Into Into Columns []Column Values Values OnConflict OnConflict Returning Returning }
Insert is a INSERT statement.
type Int64Encoder ¶
type Int64Encoder interface {
Int64() int64
}
Int64Encoder can encode a value as a int64 to creates a Value instance.
type Into ¶
type Into struct {
Table Table
}
Into is a INTO clause.
type Join ¶
type Join struct { Type types.JoinType Table Table Condition OnExpression }
Join is a JOIN clause.
func NewInnerJoin ¶
func NewInnerJoin(table Table, condition OnExpression) Join
NewInnerJoin returns a new Join instance using an INNER JOIN.
func NewJoin ¶
func NewJoin(kind types.JoinType, table Table, condition OnExpression) Join
NewJoin returns a new Join instance.
func NewLeftJoin ¶
func NewLeftJoin(table Table, condition OnExpression) Join
NewLeftJoin returns a new Join instance using a LEFT JOIN.
func NewRightJoin ¶
func NewRightJoin(table Table, condition OnExpression) Join
NewRightJoin returns a new Join instance using a RIGHT JOIN.
type Limit ¶
type Limit struct {
Count int64
}
Limit is a LIMIT clause.
type LogicalOperator ¶
type LogicalOperator struct {
Operator types.LogicalOperator
}
LogicalOperator are used to evaluate two expressions using a logical operator.
func NewAndOperator ¶
func NewAndOperator() LogicalOperator
NewAndOperator returns a new AND LogicalOperator instance.
func NewLogicalOperator ¶
func NewLogicalOperator(operator types.LogicalOperator) LogicalOperator
NewLogicalOperator returns a new LogicalOperator instance.
func NewOrOperator ¶
func NewOrOperator() LogicalOperator
NewOrOperator returns a new OR LogicalOperator instance.
func (LogicalOperator) IsEmpty ¶
func (operator LogicalOperator) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (LogicalOperator) Write ¶
func (operator LogicalOperator) Write(ctx types.Context)
Write exposes statement as a SQL query.
type Max ¶
Max is a aggregate expression.
type Min ¶
Min is a aggregate expression.
type Offset ¶
type Offset struct {
Start int64
}
Offset is a OFFSET clause.
type OnClause ¶
OnClause is a ON clause.
func NewOnClause ¶
NewOnClause returns a new On instance.
func (OnClause) And ¶
func (on OnClause) And(value OnExpression) OnExpression
And creates a new InfixOnExpression using given OnExpression.
func (OnClause) Or ¶
func (on OnClause) Or(value OnExpression) OnExpression
Or creates a new InfixOnExpression using given OnExpression.
type OnConflict ¶
type OnConflict struct { Target ConflictTarget Action ConflictAction }
OnConflict is a ON CONFLICT expression.
func NewOnConflict ¶
func NewOnConflict(target ConflictTarget, action ConflictAction) OnConflict
NewOnConflict returns a new OnConflict instance.
func (OnConflict) IsEmpty ¶
func (conflict OnConflict) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (OnConflict) Write ¶
func (conflict OnConflict) Write(ctx types.Context)
Write exposes statement as a SQL query.
type OnExpression ¶
type OnExpression interface { Statement And(value OnExpression) OnExpression Or(value OnExpression) OnExpression // contains filtered or unexported methods }
OnExpression is a SQL expression for a ON statement.
type Operator ¶
type Operator interface { Statement // contains filtered or unexported methods }
Operator are used to compose expressions.
type Order ¶
Order is an expression of a ORDER BY clause.
type OrderBy ¶
type OrderBy struct {
Orders []Order
}
OrderBy is a ORDER BY clause.
func NewOrderBy ¶
NewOrderBy returns a new OrderBy instance.
type PairContainer ¶
type PairContainer struct { Mode PairMode Map map[Column]Expression Columns []Column Expressions []Expression }
PairContainer is a composite collection that store a list of values for SET clause.
func NewPairContainer ¶
func NewPairContainer() PairContainer
NewPairContainer creates a new PairContainer.
func (*PairContainer) Add ¶
func (pairs *PairContainer) Add(column Column, expression Expression)
Add appends given column and expression. It will configure Set's syntax to key-value (a.k.a "standard", "default" or "associative").
Example:
- SET foo = 1, bar = 2, baz = 3
func (PairContainer) IsEmpty ¶
func (pairs PairContainer) IsEmpty() bool
IsEmpty returns true if statement is undefined.
func (*PairContainer) Set ¶
func (pairs *PairContainer) Set(column Column)
Set appends given column. It will configure Set's syntax to column-list. You may use Use(...) function to provide required expressions.
Example:
- SET (foo, bar, baz) = (1, 2, 3)
- SET (foo, bar, baz) = (sub-select)
func (*PairContainer) Use ¶
func (pairs *PairContainer) Use(expression Expression)
Use appends given expression if Set's syntax is defined column-list. You have to use Set(...) function to provide required columns.
Example:
- SET (foo, bar, baz) = (1, 2, 3)
- SET (foo, bar, baz) = (sub-select)
func (PairContainer) Values ¶
func (pairs PairContainer) Values() ([]Column, []Expression)
Values returns columns and expressions of current instance.
func (PairContainer) Write ¶
func (pairs PairContainer) Write(ctx types.Context)
Write exposes statement as a SQL query.
func (PairContainer) WriteArray ¶
func (pairs PairContainer) WriteArray(ctx types.Context)
WriteArray exposes statement as a SQL query using a column-list syntax.
func (PairContainer) WriteAssociative ¶
func (pairs PairContainer) WriteAssociative(ctx types.Context)
WriteAssociative exposes statement as a SQL query using a key-value syntax.
type Prefix ¶
type Prefix struct {
Prefix string
}
Prefix is a prefix expression.
type Returning ¶
type Returning struct {
Columns []Column
}
Returning is a RETURNING clause.
func NewReturning ¶
NewReturning returns a new Returning instance.
type Select ¶
type Select struct { Prefix Prefix With With Distinct bool Expressions []SelectExpression From From Joins []Join Where Where GroupBy GroupBy Having Having OrderBy OrderBy Limit Limit Offset Offset Suffix Suffix }
Select is a SELECT statement.
type SelectExpression ¶
type SelectExpression interface { Statement // contains filtered or unexported methods }
SelectExpression is a SQL expression for a SELECT statement.
type Statement ¶
type Statement interface { // IsEmpty returns true if statement is undefined. IsEmpty() bool // Write exposes statement as a SQL query. Write(ctx types.Context) }
Statement is the interface of the component which is the minimum unit constituting SQL. All types that implement this interface can be built as SQL.
type StatementEncoder ¶
type StatementEncoder interface {
Statement() Statement
}
StatementEncoder can encode a value as a statement to creates a Expression instance.
type StringEncoder ¶
type StringEncoder interface {
String() string
}
StringEncoder can encode a value as a string to creates a Value instance.
type Suffix ¶
type Suffix struct {
Suffix string
}
Suffix is a suffix expression.
type Sum ¶
Sum is a aggregate expression.
type Table ¶
Table is a table identifier.
func NewTableAlias ¶
NewTableAlias returns a new Table instance with an alias.
type TimeEncoder ¶
TimeEncoder can encode a value as a time.Time to creates a Value instance.
type Update ¶
type Update struct { With With Table Table Only bool From From Set Set Where Where Returning Returning }
Update is the UPDATE statement.
type Using ¶
type Using struct {
Tables []Table
}
Using is a USING clause.
type Value ¶
type Value struct {
Value interface{}
}
Value is an expression value.
type Values ¶
type Values struct {
Values Expression
}
Values is a VALUES clause.
type Where ¶
type Where struct {
Condition Expression
}
Where is a WHERE clause.
func (Where) And ¶
func (where Where) And(right Expression) Where
And appends given Expression using AND as logical operator.
func (Where) Or ¶
func (where Where) Or(right Expression) Where
Or appends given Expression using OR as logical operator.
type With ¶
type With struct {
Queries []WithQuery
}
With is a WITH clause.
type WithQuery ¶
type WithQuery struct { Name string Subquery Expression }
WithQuery is a statement in a With clause.
func NewWithQuery ¶
NewWithQuery returns a new WithQuery instance.
type Wrapper ¶
type Wrapper struct {
Value Expression
}
Wrapper encapsulates an expression between parenthesis.
Source Files ¶
- aggregate.go
- between.go
- column.go
- conflict.go
- delete.go
- doc.go
- encoder.go
- expression.go
- from.go
- groupby.go
- having.go
- in.go
- infix.go
- insert.go
- into.go
- join.go
- limit.go
- offset.go
- on.go
- operator.go
- order.go
- orderby.go
- prefix.go
- returning.go
- select.go
- set.go
- stmt.go
- subquery.go
- suffix.go
- table.go
- update.go
- using.go
- values.go
- where.go
- with.go