stmt

package
v2.2.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 7 Imported by: 3

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

View Source
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.

func (Array) IsEmpty

func (array Array) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Array) Write

func (array Array) Write(ctx types.Context)

Write exposes statement as a SQL query.

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.

func (Between) IsEmpty

func (between Between) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Between) Write

func (between Between) Write(ctx types.Context)

Write exposes statement as a SQL query.

type BoolEncoder

type BoolEncoder interface {
	Bool() bool
}

BoolEncoder can encode a value as a bool to creates a Value instance.

type Column

type Column struct {
	Name  string
	Alias string
}

Column is a column identifier.

func NewColumn

func NewColumn(name string) Column

NewColumn returns a new Column instance.

func NewColumnAlias

func NewColumnAlias(name, alias string) Column

NewColumnAlias returns a new Column instance with an alias.

func (Column) As

func (column Column) As(alias string) Column

As is used to give an alias name to the column.

func (Column) Asc

func (column Column) Asc() Order

Asc is used to transform a column to an order expression.

func (Column) Desc

func (column Column) Desc() Order

Desc is used to transform a column to an order expression.

func (Column) IsEmpty

func (column Column) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Column) Write

func (column Column) Write(ctx types.Context)

Write exposes statement as a SQL query.

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

type Count struct {
	Value      Raw
	IsDistinct bool
	Alias      string
}

Count is a aggregate expression.

func NewCount

func NewCount(value string) Count

NewCount returns a new Count instance.

func (Count) As

func (count Count) As(alias string) Count

As is used to give an alias name to the COUNT function.

func (Count) Distinct

func (count Count) Distinct(value bool) Count

Distinct is used to define if count has a distinct clause.

func (Count) IsEmpty

func (count Count) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Count) Write

func (count Count) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Delete

type Delete struct {
	From      From
	Using     Using
	Where     Where
	Returning Returning
}

Delete is a DELETE statement.

func NewDelete

func NewDelete() Delete

NewDelete returns a new Delete instance.

func (Delete) IsEmpty

func (delete Delete) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Delete) Write

func (delete Delete) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Exists

type Exists struct {
	Subquery Expression
}

Exists is a subquery expression.

func NewExists

func NewExists(value interface{}) Exists

NewExists returns a new Exists instance.

func (Exists) IsEmpty

func (exists Exists) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Exists) Write

func (exists Exists) Write(ctx types.Context)

Write exposes statement as a SQL query.

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

type From struct {
	Only  bool
	Table Table
}

From is a FROM clause.

func NewFrom

func NewFrom(table Table, only bool) From

NewFrom returns a new From instance.

func (From) IsEmpty

func (from From) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (From) Write

func (from From) Write(ctx types.Context)

Write exposes statement as a SQL query.

type GroupBy

type GroupBy struct {
	Columns []Column
}

GroupBy is a GROUP BY clause.

func NewGroupBy

func NewGroupBy(columns []Column) GroupBy

NewGroupBy returns a new GroupBy instance.

func (GroupBy) IsEmpty

func (group GroupBy) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (GroupBy) Write

func (group GroupBy) Write(ctx types.Context)

Write exposes statement as a SQL query.

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

func (having Having) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Having) Or

func (having Having) Or(right Expression) Having

Or appends given Expression using OR as logical operator.

func (Having) Write

func (having Having) Write(ctx types.Context)

Write exposes statement as a SQL query.

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

func (in In) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (In) Or

func (in In) Or(value Expression) InfixExpression

Or creates a new InfixExpression using given Expression.

func (In) Write

func (in In) Write(ctx types.Context)

Write exposes statement as a SQL query.

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.

func NewInsert

func NewInsert() Insert

NewInsert returns a new Insert instance.

func (Insert) IsEmpty

func (insert Insert) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Insert) Write

func (insert Insert) Write(ctx types.Context)

Write exposes statement as a SQL query.

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.

func NewInto

func NewInto(table Table) Into

NewInto returns a new Into instance.

func (Into) IsEmpty

func (into Into) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Into) Write

func (into Into) Write(ctx types.Context)

Write exposes statement as a SQL query.

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.

func (Join) IsEmpty

func (join Join) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Join) Write

func (join Join) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Limit

type Limit struct {
	Count int64
}

Limit is a LIMIT clause.

func NewLimit

func NewLimit(count int64) Limit

NewLimit returns a new Limit instance.

func (Limit) IsEmpty

func (limit Limit) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Limit) Write

func (limit Limit) Write(ctx types.Context)

Write exposes statement as a SQL query.

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

type Max struct {
	Value Raw
	Alias string
}

Max is a aggregate expression.

func NewMax

func NewMax(value string) Max

NewMax returns a new Max instance.

func (Max) As

func (max Max) As(alias string) Max

As is used to give an alias name to the MAX function.

func (Max) IsEmpty

func (max Max) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Max) Write

func (max Max) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Min

type Min struct {
	Value Raw
	Alias string
}

Min is a aggregate expression.

func NewMin

func NewMin(value string) Min

NewMin returns a new Min instance.

func (Min) As

func (min Min) As(alias string) Min

As is used to give an alias name to the MIN function.

func (Min) IsEmpty

func (min Min) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Min) Write

func (min Min) Write(ctx types.Context)

Write exposes statement as a SQL query.

type NotExists

type NotExists struct {
	Subquery Expression
}

NotExists is a subquery expression.

func NewNotExists

func NewNotExists(value interface{}) NotExists

NewNotExists returns a new NotExists instance.

func (NotExists) IsEmpty

func (nexists NotExists) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (NotExists) Write

func (nexists NotExists) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Offset

type Offset struct {
	Start int64
}

Offset is a OFFSET clause.

func NewOffset

func NewOffset(start int64) Offset

NewOffset returns a new Offset instance.

func (Offset) IsEmpty

func (offset Offset) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Offset) Write

func (offset Offset) Write(ctx types.Context)

Write exposes statement as a SQL query.

type OnClause

type OnClause struct {
	Left  Column
	Right Column
}

OnClause is a ON clause.

func NewOnClause

func NewOnClause(left, right Column) OnClause

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

func (on OnClause) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (OnClause) Or

func (on OnClause) Or(value OnExpression) OnExpression

Or creates a new InfixOnExpression using given OnExpression.

func (OnClause) Write

func (on OnClause) Write(ctx types.Context)

Write exposes statement as a SQL query.

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

type Order struct {
	Expression string
	Type       types.OrderType
}

Order is an expression of a ORDER BY clause.

func NewOrder

func NewOrder(expression string, kind types.OrderType) Order

NewOrder returns a new Order instance.

func (Order) IsEmpty

func (order Order) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Order) Write

func (order Order) Write(ctx types.Context)

Write exposes statement as a SQL query.

type OrderBy

type OrderBy struct {
	Orders []Order
}

OrderBy is a ORDER BY clause.

func NewOrderBy

func NewOrderBy(orders []Order) OrderBy

NewOrderBy returns a new OrderBy instance.

func (OrderBy) IsEmpty

func (order OrderBy) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (OrderBy) Write

func (order OrderBy) Write(ctx types.Context)

Write exposes statement as a SQL query.

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 PairMode

type PairMode uint8

PairMode define the mode of PairContainer.

type Prefix

type Prefix struct {
	Prefix string
}

Prefix is a prefix expression.

func NewPrefix

func NewPrefix(prefix string) Prefix

NewPrefix returns a new Prefix instance.

func (Prefix) IsEmpty

func (prefix Prefix) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Prefix) Write

func (prefix Prefix) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Raw

type Raw struct {
	Value string
}

Raw is a raw expression value.

func NewRaw

func NewRaw(value string) Raw

NewRaw returns a raw expression value.

func (Raw) IsEmpty

func (raw Raw) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Raw) Write

func (raw Raw) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Returning

type Returning struct {
	Columns []Column
}

Returning is a RETURNING clause.

func NewReturning

func NewReturning(columns []Column) Returning

NewReturning returns a new Returning instance.

func (Returning) IsEmpty

func (returning Returning) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Returning) Write

func (returning Returning) Write(ctx types.Context)

Write exposes statement as a SQL query.

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.

func NewSelect

func NewSelect() Select

NewSelect returns a new Select instance.

func (Select) IsEmpty

func (selekt Select) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Select) Write

func (selekt Select) Write(ctx types.Context)

Write exposes statement as a SQL query.

type SelectExpression

type SelectExpression interface {
	Statement
	// contains filtered or unexported methods
}

SelectExpression is a SQL expression for a SELECT statement.

type Set

type Set struct {
	Pairs PairContainer
}

Set is a SET clause.

func NewSet

func NewSet() Set

NewSet returns a new Set instance.

func (Set) IsEmpty

func (set Set) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Set) Write

func (set Set) Write(ctx types.Context)

Write exposes statement as a SQL query.

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.

func NewSuffix

func NewSuffix(suffix string) Suffix

NewSuffix returns a new Suffix instance.

func (Suffix) IsEmpty

func (suffix Suffix) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Suffix) Write

func (suffix Suffix) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Sum

type Sum struct {
	Value Raw
	Alias string
}

Sum is a aggregate expression.

func NewSum

func NewSum(value string) Sum

NewSum returns a new Sum instance.

func (Sum) As

func (sum Sum) As(alias string) Sum

As is used to give an alias name to the SUM function.

func (Sum) IsEmpty

func (sum Sum) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Sum) Write

func (sum Sum) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Table

type Table struct {
	Name  string
	Alias string
}

Table is a table identifier.

func NewTable

func NewTable(name string) Table

NewTable returns a new Table instance.

func NewTableAlias

func NewTableAlias(name, alias string) Table

NewTableAlias returns a new Table instance with an alias.

func (Table) As

func (table Table) As(alias string) Table

As is used to give an alias name to the column.

func (Table) IsEmpty

func (table Table) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Table) Write

func (table Table) Write(ctx types.Context)

Write exposes statement as a SQL query.

type TimeEncoder

type TimeEncoder interface {
	Time() time.Time
}

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.

func NewUpdate

func NewUpdate(table Table) Update

NewUpdate returns a new Update instance.

func (Update) IsEmpty

func (update Update) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Update) Write

func (update Update) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Using

type Using struct {
	Tables []Table
}

Using is a USING clause.

func NewUsing

func NewUsing(tables []Table) Using

NewUsing returns a new Using instance.

func (Using) IsEmpty

func (using Using) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Using) Write

func (using Using) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Value

type Value struct {
	Value interface{}
}

Value is an expression value.

func NewValue

func NewValue(value interface{}) Value

NewValue returns an expression value.

func (Value) IsEmpty

func (value Value) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Value) Write

func (value Value) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Values

type Values struct {
	Values Expression
}

Values is a VALUES clause.

func NewValues

func NewValues(values Expression) Values

NewValues returns a new Values instance.

func (Values) IsEmpty

func (values Values) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Values) Write

func (values Values) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Where

type Where struct {
	Condition Expression
}

Where is a WHERE clause.

func NewWhere

func NewWhere(expression Expression) Where

NewWhere returns a new Where instance.

func (Where) And

func (where Where) And(right Expression) Where

And appends given Expression using AND as logical operator.

func (Where) IsEmpty

func (where Where) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Where) Or

func (where Where) Or(right Expression) Where

Or appends given Expression using OR as logical operator.

func (Where) Write

func (where Where) Write(ctx types.Context)

Write exposes statement as a SQL query.

type With

type With struct {
	Queries []WithQuery
}

With is a WITH clause.

func NewWith

func NewWith(queries []WithQuery) With

NewWith returns a new With instance.

func (With) IsEmpty

func (with With) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (With) Write

func (with With) Write(ctx types.Context)

Write exposes statement as a SQL query.

type WithQuery

type WithQuery struct {
	Name     string
	Subquery Expression
}

WithQuery is a statement in a With clause.

func NewWithQuery

func NewWithQuery(name string, value interface{}) WithQuery

NewWithQuery returns a new WithQuery instance.

func (WithQuery) IsEmpty

func (with WithQuery) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (WithQuery) Write

func (with WithQuery) Write(ctx types.Context)

Write exposes statement as a SQL query.

type Wrapper

type Wrapper struct {
	Value Expression
}

Wrapper encapsulates an expression between parenthesis.

func (Wrapper) IsEmpty

func (wrapper Wrapper) IsEmpty() bool

IsEmpty returns true if statement is undefined.

func (Wrapper) Write

func (wrapper Wrapper) Write(ctx types.Context)

Write exposes statement as a SQL query.

Jump to

Keyboard shortcuts

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