Documentation ¶
Index ¶
- Variables
- func InterfaceSlice(slice interface{}) []interface{}
- type Buffer
- type DDL
- type DeleteStatement
- func (s *DeleteStatement) Build(buf Buffer) (err error)
- func (s *DeleteStatement) Comment(c string, values ...interface{}) *DeleteStatement
- func (s *DeleteStatement) From(table string) *DeleteStatement
- func (s *DeleteStatement) Returning(columns ...string) *DeleteStatement
- func (s *DeleteStatement) String() (q string, err error)
- func (s *DeleteStatement) Where(q string, values ...interface{}) *DeleteStatement
- func (s *DeleteStatement) WhereIn(column string, values ...interface{}) *DeleteStatement
- func (s *DeleteStatement) With(alias string, stmt Statement) *DeleteStatement
- type Ident
- type InsertStatement
- func (s *InsertStatement) Build(buf Buffer) (err error)
- func (s *InsertStatement) Columns(columns ...string) (st *InsertStatement)
- func (s *InsertStatement) Comment(c string, values ...interface{}) *InsertStatement
- func (s *InsertStatement) Into(table string) (st *InsertStatement)
- func (s *InsertStatement) OnConflict(q string, values ...interface{}) (st *InsertStatement)
- func (s *InsertStatement) Record(structValue interface{}) (st *InsertStatement)
- func (s *InsertStatement) Returning(columns ...string) *InsertStatement
- func (s *InsertStatement) String() (q string, err error)
- func (s *InsertStatement) Values(values ...interface{}) (st *InsertStatement)
- func (s *InsertStatement) ValuesSelect(values *SelectStatement) (st *InsertStatement)
- func (s *InsertStatement) With(alias string, stmt Statement) *InsertStatement
- type Join
- type Part
- type SelectStatement
- func (s *SelectStatement) Build(buf Buffer) (err error)
- func (s *SelectStatement) Column(q string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) Columns(columns ...interface{}) *SelectStatement
- func (s *SelectStatement) Comment(c string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) Distinct() *SelectStatement
- func (s *SelectStatement) ForUpdate() *SelectStatement
- func (s *SelectStatement) From(table interface{}) *SelectStatement
- func (s *SelectStatement) GroupBy(columns ...string) *SelectStatement
- func (s *SelectStatement) Having(q string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) Join(join Join, table, cond string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) JoinFull(table, cond string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) JoinInner(table, cond string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) JoinLeft(table, cond string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) JoinRight(table, cond string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) Limit(n int64) *SelectStatement
- func (s *SelectStatement) Offset(n int64) *SelectStatement
- func (s *SelectStatement) OrderAsc(columns ...string) *SelectStatement
- func (s *SelectStatement) OrderDesc(columns ...string) *SelectStatement
- func (s *SelectStatement) SkipLocked() *SelectStatement
- func (s *SelectStatement) String() (q string, err error)
- func (s *SelectStatement) Union(stmt Statement) *SelectStatement
- func (s *SelectStatement) UnionAll(stmt Statement) *SelectStatement
- func (s *SelectStatement) Where(q string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) WhereIn(column string, values ...interface{}) *SelectStatement
- func (s *SelectStatement) With(alias string, stmt Statement) *SelectStatement
- func (s *SelectStatement) WithRecursive(alias string, stmt Statement) *SelectStatement
- type Statement
- type UpdateStatement
- func (s *UpdateStatement) Build(buf Buffer) (err error)
- func (s *UpdateStatement) Comment(c string, values ...interface{}) *UpdateStatement
- func (s *UpdateStatement) Returning(columns ...string) *UpdateStatement
- func (s *UpdateStatement) Set(column string, value interface{}) *UpdateStatement
- func (s *UpdateStatement) SetMap(m map[string]interface{}) *UpdateStatement
- func (s *UpdateStatement) String() (q string, err error)
- func (s *UpdateStatement) Table(table string) *UpdateStatement
- func (s *UpdateStatement) Where(q string, values ...interface{}) *UpdateStatement
- func (s *UpdateStatement) WhereIn(column string, values ...interface{}) *UpdateStatement
- func (s *UpdateStatement) With(alias string, stmt Statement) *UpdateStatement
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyWithAlias will be returned when the a alias for a with clause is empty ErrEmptyWithAlias = fmt.Errorf("statement: empty with clause alias") // ErrInvalidArgNumber will be returned when there is a mismatch between placeholders and values for interpolation. ErrInvalidArgNumber = fmt.Errorf("statement: invalid number of arguments") )
Functions ¶
func InterfaceSlice ¶
func InterfaceSlice(slice interface{}) []interface{}
InterfaceSlice converts any slice to a []interface{}
Types ¶
type Buffer ¶
Buffer represents the write buffer for building statements. Fits nicely with a strings.Builder or a bytes.Buffer.
type DDL ¶
type DDL struct { *Part // contains filtered or unexported fields }
DDL represents a data definition statement.
type DeleteStatement ¶
type DeleteStatement struct {
// contains filtered or unexported fields
}
DeleteStatement statement.
func (*DeleteStatement) Build ¶
func (s *DeleteStatement) Build(buf Buffer) (err error)
Build builds the statement into the given buffer.
func (*DeleteStatement) Comment ¶
func (s *DeleteStatement) Comment(c string, values ...interface{}) *DeleteStatement
Comment adds a SQL comment to the generated query. Each call to comment creates a new `-- <comment>` line.
func (*DeleteStatement) From ¶
func (s *DeleteStatement) From(table string) *DeleteStatement
From sets the table name or for the `FROM` clause.
func (*DeleteStatement) Returning ¶
func (s *DeleteStatement) Returning(columns ...string) *DeleteStatement
Returning adds a `RETURNING columns` clause.
func (*DeleteStatement) String ¶
func (s *DeleteStatement) String() (q string, err error)
String builds the statement and returns the resulting query string.
func (*DeleteStatement) Where ¶
func (s *DeleteStatement) Where(q string, values ...interface{}) *DeleteStatement
Where adds a `WHERE` clause, multiple calls to Where are `ANDed` together.
func (*DeleteStatement) WhereIn ¶
func (s *DeleteStatement) WhereIn(column string, values ...interface{}) *DeleteStatement
WhereIn adds a `WHERE IN (values)` clause, multiple calls to WhereIn are `ANDed` together.
func (*DeleteStatement) With ¶
func (s *DeleteStatement) With(alias string, stmt Statement) *DeleteStatement
With adds a `WITH alias AS (stmt)`
type Ident ¶ added in v0.2.12
type Ident string
Ident type is handled as an user provided identifier as is in the resulting query
type InsertStatement ¶
type InsertStatement struct {
// contains filtered or unexported fields
}
InsertStatement statement.
func (*InsertStatement) Build ¶
func (s *InsertStatement) Build(buf Buffer) (err error)
Build builds the statement into the given buffer.
func (*InsertStatement) Columns ¶
func (s *InsertStatement) Columns(columns ...string) (st *InsertStatement)
Columns specifies the columns for the `INSERT` statement.
func (*InsertStatement) Comment ¶
func (s *InsertStatement) Comment(c string, values ...interface{}) *InsertStatement
Comment adds a SQL comment to the generated query. Each call to comment creates a new `-- <comment>` line.
func (*InsertStatement) Into ¶
func (s *InsertStatement) Into(table string) (st *InsertStatement)
Into specifies the table on which to perform the insert
func (*InsertStatement) OnConflict ¶ added in v0.2.1
func (s *InsertStatement) OnConflict(q string, values ...interface{}) (st *InsertStatement)
OnConflict adds a `ON CONFLICT` clause.
func (*InsertStatement) Record ¶
func (s *InsertStatement) Record(structValue interface{}) (st *InsertStatement)
Record add the values from the given struct for insert. If no columns where specified before calling Record(), the columns will be defined by the struct fields.
func (*InsertStatement) Returning ¶
func (s *InsertStatement) Returning(columns ...string) *InsertStatement
Returning adds a `RETURNING columns` clause.
func (*InsertStatement) String ¶
func (s *InsertStatement) String() (q string, err error)
String builds the statement and returns the resulting query string.
func (*InsertStatement) Values ¶
func (s *InsertStatement) Values(values ...interface{}) (st *InsertStatement)
Values specifies the values for the `VALUES` clause.
func (*InsertStatement) ValuesSelect ¶
func (s *InsertStatement) ValuesSelect(values *SelectStatement) (st *InsertStatement)
ValuesSelect specifies a Select statement from which values will be inserted.
func (*InsertStatement) With ¶
func (s *InsertStatement) With(alias string, stmt Statement) *InsertStatement
With adds a `WITH alias AS (stmt)`
type Part ¶ added in v0.2.2
type Part struct { Query string Values []interface{} }
Part is a query fragment that satisfies the statement.Statement interface
type SelectStatement ¶
type SelectStatement struct {
// contains filtered or unexported fields
}
SelectStatement statement.
func (*SelectStatement) Build ¶
func (s *SelectStatement) Build(buf Buffer) (err error)
Build builds the statement into the given buffer.
func (*SelectStatement) Column ¶ added in v0.2.9
func (s *SelectStatement) Column(q string, values ...interface{}) *SelectStatement
Column append the given column to the `SELECT`. Column appends to the existing columns already specified. Used for more ellaborate column specification.
func (*SelectStatement) Columns ¶
func (s *SelectStatement) Columns(columns ...interface{}) *SelectStatement
Columns set the `SELECT` columns. Columns overwrites any previously set columns for this statement.
func (*SelectStatement) Comment ¶
func (s *SelectStatement) Comment(c string, values ...interface{}) *SelectStatement
Comment adds a SQL comment to the generated query. Each call to comment creates a new `-- <comment>` line.
func (*SelectStatement) Distinct ¶
func (s *SelectStatement) Distinct() *SelectStatement
Distinct adds a `DISTINCT` clause.
func (*SelectStatement) ForUpdate ¶
func (s *SelectStatement) ForUpdate() *SelectStatement
ForUpdate a `FOR UPDATE` clause.
func (*SelectStatement) From ¶
func (s *SelectStatement) From(table interface{}) *SelectStatement
From sets the table name or *Select statement for the `FROM` clause.
func (*SelectStatement) GroupBy ¶
func (s *SelectStatement) GroupBy(columns ...string) *SelectStatement
GroupBy adds a `GROUP BY columns` clause.
func (*SelectStatement) Having ¶
func (s *SelectStatement) Having(q string, values ...interface{}) *SelectStatement
Having adds a `HAVING` clause, multiple calls to Having are `ANDed` together.
func (*SelectStatement) Join ¶
func (s *SelectStatement) Join(join Join, table, cond string, values ...interface{}) *SelectStatement
Join adds a `JOIN ...` clause.
func (*SelectStatement) JoinFull ¶
func (s *SelectStatement) JoinFull(table, cond string, values ...interface{}) *SelectStatement
JoinFull adds a `FULL OUTER JOIN` clause.
func (*SelectStatement) JoinInner ¶
func (s *SelectStatement) JoinInner(table, cond string, values ...interface{}) *SelectStatement
JoinInner adds a `INNER JOIN` clause.
func (*SelectStatement) JoinLeft ¶
func (s *SelectStatement) JoinLeft(table, cond string, values ...interface{}) *SelectStatement
JoinLeft adds a `LEFT OUTER JOIN` clause.
func (*SelectStatement) JoinRight ¶
func (s *SelectStatement) JoinRight(table, cond string, values ...interface{}) *SelectStatement
JoinRight adds a `RIGHT OUTER JOIN` clause.
func (*SelectStatement) Limit ¶
func (s *SelectStatement) Limit(n int64) *SelectStatement
Limit adds a `LIMIT n` clause.
func (*SelectStatement) Offset ¶
func (s *SelectStatement) Offset(n int64) *SelectStatement
Offset adds a `OFFSET n` clause, only if LIMIT is also set.
func (*SelectStatement) OrderAsc ¶
func (s *SelectStatement) OrderAsc(columns ...string) *SelectStatement
OrderAsc adds a `ORDER BY columns ASC` clause.
func (*SelectStatement) OrderDesc ¶
func (s *SelectStatement) OrderDesc(columns ...string) *SelectStatement
OrderDesc adds a `ORDER BY columns DESC` clause.
func (*SelectStatement) SkipLocked ¶
func (s *SelectStatement) SkipLocked() *SelectStatement
SkipLocked adds a `SKIP LOCKED` clause.
func (*SelectStatement) String ¶
func (s *SelectStatement) String() (q string, err error)
String builds the statement and returns the resulting query string.
func (*SelectStatement) Union ¶
func (s *SelectStatement) Union(stmt Statement) *SelectStatement
Union adds a `UNION` clause.
func (*SelectStatement) UnionAll ¶
func (s *SelectStatement) UnionAll(stmt Statement) *SelectStatement
UnionAll adds a `UNION ALL` clause.
func (*SelectStatement) Where ¶
func (s *SelectStatement) Where(q string, values ...interface{}) *SelectStatement
Where adds a `WHERE` clause, multiple calls to Where are `ANDed` together.
func (*SelectStatement) WhereIn ¶
func (s *SelectStatement) WhereIn(column string, values ...interface{}) *SelectStatement
WhereIn adds a `WHERE IN (values)` clause, multiple calls to WhereIn are `ANDed` together.
func (*SelectStatement) With ¶
func (s *SelectStatement) With(alias string, stmt Statement) *SelectStatement
With adds a `WITH alias AS (stmt)`
func (*SelectStatement) WithRecursive ¶
func (s *SelectStatement) WithRecursive(alias string, stmt Statement) *SelectStatement
WithRecursive adds a `WITH RECURSIVE alias AS (stmt)`
type UpdateStatement ¶
type UpdateStatement struct {
// contains filtered or unexported fields
}
UpdateStatement statement.
func (*UpdateStatement) Build ¶
func (s *UpdateStatement) Build(buf Buffer) (err error)
Build builds the statement into the given buffer.
func (*UpdateStatement) Comment ¶
func (s *UpdateStatement) Comment(c string, values ...interface{}) *UpdateStatement
Comment adds a SQL comment to the generated query. Each call to comment creates a new `-- <comment>` line.
func (*UpdateStatement) Returning ¶
func (s *UpdateStatement) Returning(columns ...string) *UpdateStatement
Returning adds a `RETURNING columns` clause.
func (*UpdateStatement) Set ¶
func (s *UpdateStatement) Set(column string, value interface{}) *UpdateStatement
Set adds a `SET column = value` clause, multiple calls to set append additional updates `SET column = value, column = value`
func (*UpdateStatement) SetMap ¶
func (s *UpdateStatement) SetMap(m map[string]interface{}) *UpdateStatement
SetMap specifies a map of column-value pairs to be updated.
func (*UpdateStatement) String ¶
func (s *UpdateStatement) String() (q string, err error)
String builds the statement and returns the resulting query string.
func (*UpdateStatement) Table ¶
func (s *UpdateStatement) Table(table string) *UpdateStatement
Table specifies the table for update.
func (*UpdateStatement) Where ¶
func (s *UpdateStatement) Where(q string, values ...interface{}) *UpdateStatement
Where adds a `WHERE` clause, multiple calls to Where are `ANDed` together.
func (*UpdateStatement) WhereIn ¶
func (s *UpdateStatement) WhereIn(column string, values ...interface{}) *UpdateStatement
WhereIn adds a `WHERE IN (values)` clause, multiple calls to WhereIn are `ANDed` together.
func (*UpdateStatement) With ¶
func (s *UpdateStatement) With(alias string, stmt Statement) *UpdateStatement
With adds a `WITH alias AS (stmt)` clause.