Documentation
¶
Index ¶
- func Flatten(slices interface{}) (flattened []interface{})
- func List(arg interface{}) interface{}
- func Named(name string, arg interface{}) interface{}
- func Raw(expr string) interface{}
- type Args
- type Builder
- type Cond
- func (c *Cond) All(field, op string, value ...interface{}) string
- func (c *Cond) And(andExpr ...string) string
- func (c *Cond) Any(field, op string, value ...interface{}) string
- func (c *Cond) Between(field string, lower, upper interface{}) string
- func (c *Cond) EQ(field string, value interface{}) string
- func (c *Cond) Exists(subquery interface{}) string
- func (c *Cond) Expr(field string, op string, value interface{}) string
- func (c *Cond) GE(field string, value interface{}) string
- func (c *Cond) GT(field string, value interface{}) string
- func (c *Cond) In(field string, value ...interface{}) string
- func (c *Cond) IsNotNull(field string) string
- func (c *Cond) IsNull(field string) string
- func (c *Cond) LE(field string, value interface{}) string
- func (c *Cond) LT(field string, value interface{}) string
- func (c *Cond) Like(field string, value interface{}) string
- func (c *Cond) NE(field string, value interface{}) string
- func (c *Cond) NotBetween(field string, lower, upper interface{}) string
- func (c *Cond) NotExists(subquery interface{}) string
- func (c *Cond) NotIn(field string, value ...interface{}) string
- func (c *Cond) NotLike(field string, value interface{}) string
- func (c *Cond) Or(orExpr ...string) string
- func (c *Cond) Some(field, op string, value ...interface{}) string
- func (c *Cond) Var(value interface{}) string
- type DeleteBuilder
- func (db *DeleteBuilder) Asc() *DeleteBuilder
- func (db *DeleteBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
- func (db *DeleteBuilder) DeleteFrom(table string) *DeleteBuilder
- func (db *DeleteBuilder) Desc() *DeleteBuilder
- func (db *DeleteBuilder) Limit(limit int) *DeleteBuilder
- func (db *DeleteBuilder) OrderBy(col ...string) *DeleteBuilder
- func (db *DeleteBuilder) String() string
- func (db *DeleteBuilder) Where(andExpr ...string) *DeleteBuilder
- type InsertBuilder
- func (ub *InsertBuilder) Assign(field string, value interface{}) string
- func (ib *InsertBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
- func (ib *InsertBuilder) Cols(col ...string) *InsertBuilder
- func (ib *InsertBuilder) DoUpdate(assignment ...string) *InsertBuilder
- func (ib *InsertBuilder) InsertInto(table string) *InsertBuilder
- func (ib *InsertBuilder) OnConflict(col ...string) *InsertBuilder
- func (ib *InsertBuilder) Returning(col ...string) *InsertBuilder
- func (ub *InsertBuilder) Set(col string) string
- func (ib *InsertBuilder) Values(value ...interface{}) *InsertBuilder
- func (ib *InsertBuilder) Var(arg interface{}) string
- type JoinOption
- type SelectBuilder
- func (sb *SelectBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
- func (sb *SelectBuilder) BuilderAs(builder Builder, alias string) string
- func (sb *SelectBuilder) From(table ...string) *SelectBuilder
- func (sb *SelectBuilder) GroupBy(col ...string) *SelectBuilder
- func (sb *SelectBuilder) Having(andExpr ...string) *SelectBuilder
- func (sb *SelectBuilder) Join(table string, onExpr ...string) *SelectBuilder
- func (sb *SelectBuilder) JoinWithOption(option JoinOption, table string, onExpr ...string) *SelectBuilder
- func (sb *SelectBuilder) LeftJoin(table string, onExpr ...string) *SelectBuilder
- func (sb *SelectBuilder) Limit(limit int) *SelectBuilder
- func (sb *SelectBuilder) Offset(offset int) *SelectBuilder
- func (sb *SelectBuilder) OrderBy(order string, col ...string) *SelectBuilder
- func (sb *SelectBuilder) OrderByAsc(col ...string) *SelectBuilder
- func (sb *SelectBuilder) OrderByDesc(col ...string) *SelectBuilder
- func (sb *SelectBuilder) Select(col ...string) *SelectBuilder
- func (sb *SelectBuilder) Where(andExpr ...string) *SelectBuilder
- type UnionBuilder
- func (ub *UnionBuilder) Asc() *UnionBuilder
- func (ub *UnionBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
- func (ub *UnionBuilder) Desc() *UnionBuilder
- func (ub *UnionBuilder) Limit(limit int) *UnionBuilder
- func (ub *UnionBuilder) Offset(offset int) *UnionBuilder
- func (ub *UnionBuilder) OrderBy(col ...string) *UnionBuilder
- func (ub *UnionBuilder) Union(builders ...Builder) *UnionBuilder
- func (ub *UnionBuilder) UnionAll(builders ...Builder) *UnionBuilder
- func (ub *UnionBuilder) Var(arg interface{}) string
- type UpdateBuilder
- func (ub *UpdateBuilder) Add(field string, value interface{}) string
- func (ub *UpdateBuilder) Asc() *UpdateBuilder
- func (ub *UpdateBuilder) Assign(field string, value interface{}) string
- func (ub *UpdateBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
- func (ub *UpdateBuilder) Decr(field string) string
- func (ub *UpdateBuilder) Desc() *UpdateBuilder
- func (ub *UpdateBuilder) Div(field string, value interface{}) string
- func (ub *UpdateBuilder) Incr(field string) string
- func (ub *UpdateBuilder) Limit(limit int) *UpdateBuilder
- func (ub *UpdateBuilder) Mul(field string, value interface{}) string
- func (ub *UpdateBuilder) OrderBy(col ...string) *UpdateBuilder
- func (ub *UpdateBuilder) Set(assignment ...string) *UpdateBuilder
- func (ub *UpdateBuilder) SetMore(assignment ...string) *UpdateBuilder
- func (ub *UpdateBuilder) Sub(field string, value interface{}) string
- func (ub *UpdateBuilder) Update(table string) *UpdateBuilder
- func (ub *UpdateBuilder) Where(andExpr ...string) *UpdateBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flatten ¶
func Flatten(slices interface{}) (flattened []interface{})
Flatten recursively extracts values in slices and returns a flattened []interface{} with all values. If slices is not a slice, return `[]interface{}{slices}`.
func List ¶
func List(arg interface{}) interface{}
List marks arg as a list of data. If arg is `[]int{1, 2, 3}`, it will be compiled to `?, ?, ?` with args `[1 2 3]`.
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
Args stores arguments associated with a SQL.
func (*Args) Compile ¶
func (args *Args) Compile(format string, initialValue ...interface{}) (query string, values []interface{})
Compile compiles builder's format to standard sql and returns associated args.
The format string uses a special syntax to represent arguments.
$? refers successive arguments passed in the call. It works similar as `%v` in `fmt.Sprintf`. $0 $1 ... $n refers nth-argument passed in the call. Next $? will use arguments n+1. ${name} refers a named argument created by `Named` with `name`. $$ is a "$" string.
type Builder ¶
type Builder interface {
Build(initialArg ...interface{}) (sql string, args []interface{})
}
Builder is a general SQL builder. It's used by Args to create nested SQL like the `IN` expression in `SELECT * FROM t1 WHERE id IN (SELECT id FROM t2)`.
type Cond ¶
type Cond struct {
Args *Args
}
Cond provides several helper methods to build conditions.
func (*Cond) NotBetween ¶
NotBetween represents "field NOT BETWEEN lower AND upper".
type DeleteBuilder ¶
type DeleteBuilder struct { Cond // contains filtered or unexported fields }
DeleteBuilder is a builder to build DELETE.
func DeleteFrom ¶
func DeleteFrom(table string) *DeleteBuilder
DeleteFrom sets table name in DELETE.
func NewDeleteBuilder ¶
func NewDeleteBuilder() *DeleteBuilder
NewDeleteBuilder creates a new DELETE builder.
func (*DeleteBuilder) Asc ¶
func (db *DeleteBuilder) Asc() *DeleteBuilder
Asc sets order of ORDER BY to ASC.
func (*DeleteBuilder) Build ¶
func (db *DeleteBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
Build returns compiled DELETE string and args. They can be used in `DB#Query` of package `database/sql` directly.
func (*DeleteBuilder) DeleteFrom ¶
func (db *DeleteBuilder) DeleteFrom(table string) *DeleteBuilder
DeleteFrom sets table name in DELETE.
func (*DeleteBuilder) Desc ¶
func (db *DeleteBuilder) Desc() *DeleteBuilder
Desc sets order of ORDER BY to DESC.
func (*DeleteBuilder) Limit ¶
func (db *DeleteBuilder) Limit(limit int) *DeleteBuilder
Limit sets the LIMIT in DELETE.
func (*DeleteBuilder) OrderBy ¶
func (db *DeleteBuilder) OrderBy(col ...string) *DeleteBuilder
OrderBy sets columns of ORDER BY in DELETE.
func (*DeleteBuilder) String ¶
func (db *DeleteBuilder) String() string
String returns the compiled DELETE string.
func (*DeleteBuilder) Where ¶
func (db *DeleteBuilder) Where(andExpr ...string) *DeleteBuilder
Where sets expressions of WHERE in DELETE.
type InsertBuilder ¶
type InsertBuilder struct {
// contains filtered or unexported fields
}
InsertBuilder is a builder to build INSERT.
func InsertInto ¶
func InsertInto(table string) *InsertBuilder
InsertInto sets table name in INSERT.
func NewInsertBuilder ¶
func NewInsertBuilder() *InsertBuilder
NewInsertBuilder creates a new INSERT builder.
func (*InsertBuilder) Assign ¶
func (ub *InsertBuilder) Assign(field string, value interface{}) string
Assign represents SET "field = value" in UPDATE.
func (*InsertBuilder) Build ¶
func (ib *InsertBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
BuildWithFlavor returns compiled INSERT string and args with flavor and initial args. They can be used in `DB#Query` of package `database/sql` directly.
func (*InsertBuilder) Cols ¶
func (ib *InsertBuilder) Cols(col ...string) *InsertBuilder
Cols sets columns in INSERT.
func (*InsertBuilder) DoUpdate ¶
func (ib *InsertBuilder) DoUpdate(assignment ...string) *InsertBuilder
Cols sets columns in INSERT.
func (*InsertBuilder) InsertInto ¶
func (ib *InsertBuilder) InsertInto(table string) *InsertBuilder
InsertInto sets table name in INSERT.
func (*InsertBuilder) OnConflict ¶
func (ib *InsertBuilder) OnConflict(col ...string) *InsertBuilder
Cols sets columns in INSERT.
func (*InsertBuilder) Returning ¶
func (ib *InsertBuilder) Returning(col ...string) *InsertBuilder
func (*InsertBuilder) Set ¶
func (ub *InsertBuilder) Set(col string) string
Assign represents SET "field = value" in UPDATE.
func (*InsertBuilder) Values ¶
func (ib *InsertBuilder) Values(value ...interface{}) *InsertBuilder
Values adds a list of values for a row in INSERT.
func (*InsertBuilder) Var ¶
func (ib *InsertBuilder) Var(arg interface{}) string
Var returns a placeholder for value.
type JoinOption ¶
type JoinOption string
JoinOption is the option in JOIN.
const ( FullJoin JoinOption = "FULL" FullOuterJoin JoinOption = "FULL OUTER" InnerJoin JoinOption = "INNER" LeftJoin JoinOption = "LEFT" LeftOuterJoin JoinOption = "LEFT OUTER" RightJoin JoinOption = "RIGHT" RightOuterJoin JoinOption = "RIGHT OUTER" )
Join options.
type SelectBuilder ¶
type SelectBuilder struct { Cond // contains filtered or unexported fields }
SelectBuilder is a builder to build SELECT.
func NewSelectBuilder ¶
func NewSelectBuilder() *SelectBuilder
NewSelectBuilder creates a new SELECT builder.
func Select ¶
func Select(col ...string) *SelectBuilder
func (*SelectBuilder) Build ¶
func (sb *SelectBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
BuildWithFlavor returns compiled SELECT string and args with flavor and initial args. They can be used in `DB#Query` of package `database/sql` directly.
func (*SelectBuilder) BuilderAs ¶
func (sb *SelectBuilder) BuilderAs(builder Builder, alias string) string
BuilderAs returns an AS expression wrapping a complex SQL. According to SQL syntax, SQL built by builder is surrounded by parens.
func (*SelectBuilder) From ¶
func (sb *SelectBuilder) From(table ...string) *SelectBuilder
From sets table names in SELECT.
func (*SelectBuilder) GroupBy ¶
func (sb *SelectBuilder) GroupBy(col ...string) *SelectBuilder
GroupBy sets columns of GROUP BY in SELECT.
func (*SelectBuilder) Having ¶
func (sb *SelectBuilder) Having(andExpr ...string) *SelectBuilder
Having sets expressions of HAVING in SELECT.
func (*SelectBuilder) Join ¶
func (sb *SelectBuilder) Join(table string, onExpr ...string) *SelectBuilder
Join sets expressions of JOIN in SELECT.
It builds a JOIN expression like
JOIN table ON onExpr[0] AND onExpr[1] ...
func (*SelectBuilder) JoinWithOption ¶
func (sb *SelectBuilder) JoinWithOption(option JoinOption, table string, onExpr ...string) *SelectBuilder
JoinWithOption sets expressions of JOIN with an option.
It builds a JOIN expression like
option JOIN table ON onExpr[0] AND onExpr[1] ...
Here is a list of supported options.
- FullJoin: FULL JOIN
- FullOuterJoin: FULL OUTER JOIN
- InnerJoin: INNER JOIN
- LeftJoin: LEFT JOIN
- LeftOuterJoin: LEFT OUTER JOIN
- RightJoin: RIGHT JOIN
- RightOuterJoin: RIGHT OUTER JOIN
func (*SelectBuilder) LeftJoin ¶
func (sb *SelectBuilder) LeftJoin(table string, onExpr ...string) *SelectBuilder
func (*SelectBuilder) Limit ¶
func (sb *SelectBuilder) Limit(limit int) *SelectBuilder
func (*SelectBuilder) Offset ¶
func (sb *SelectBuilder) Offset(offset int) *SelectBuilder
Offset sets the LIMIT offset in SELECT.
func (*SelectBuilder) OrderBy ¶
func (sb *SelectBuilder) OrderBy(order string, col ...string) *SelectBuilder
OrderBy sets columns of ORDER BY in SELECT with the provided order.
func (*SelectBuilder) OrderByAsc ¶
func (sb *SelectBuilder) OrderByAsc(col ...string) *SelectBuilder
OrderByAsc sets columns of ORDER BY ASC in SELECT.
func (*SelectBuilder) OrderByDesc ¶
func (sb *SelectBuilder) OrderByDesc(col ...string) *SelectBuilder
OrderByDesc sets columns of ORDER BY DESC in SELECT.
func (*SelectBuilder) Select ¶
func (sb *SelectBuilder) Select(col ...string) *SelectBuilder
func (*SelectBuilder) Where ¶
func (sb *SelectBuilder) Where(andExpr ...string) *SelectBuilder
type UnionBuilder ¶
type UnionBuilder struct {
// contains filtered or unexported fields
}
UnionBuilder is a builder to build UNION.
func NewUnionBuilder ¶
func NewUnionBuilder() *UnionBuilder
NewUnionBuilder creates a new UNION builder.
func Union ¶
func Union(builders ...Builder) *UnionBuilder
Union unions all builders together using UNION operator.
func UnionAll ¶
func UnionAll(builders ...Builder) *UnionBuilder
UnionAll unions all builders together using UNION ALL operator.
func (*UnionBuilder) Asc ¶
func (ub *UnionBuilder) Asc() *UnionBuilder
Asc sets order of ORDER BY to ASC.
func (*UnionBuilder) Build ¶
func (ub *UnionBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
Build returns compiled SELECT string and args. They can be used in `DB#Query` of package `database/sql` directly.
func (*UnionBuilder) Desc ¶
func (ub *UnionBuilder) Desc() *UnionBuilder
Desc sets order of ORDER BY to DESC.
func (*UnionBuilder) Limit ¶
func (ub *UnionBuilder) Limit(limit int) *UnionBuilder
Limit sets the LIMIT in SELECT.
func (*UnionBuilder) Offset ¶
func (ub *UnionBuilder) Offset(offset int) *UnionBuilder
Offset sets the LIMIT offset in SELECT.
func (*UnionBuilder) OrderBy ¶
func (ub *UnionBuilder) OrderBy(col ...string) *UnionBuilder
OrderBy sets columns of ORDER BY in SELECT.
func (*UnionBuilder) Union ¶
func (ub *UnionBuilder) Union(builders ...Builder) *UnionBuilder
Union unions all builders together using UNION operator.
func (*UnionBuilder) UnionAll ¶
func (ub *UnionBuilder) UnionAll(builders ...Builder) *UnionBuilder
UnionAll unions all builders together using UNION ALL operator.
func (*UnionBuilder) Var ¶
func (ub *UnionBuilder) Var(arg interface{}) string
Var returns a placeholder for value.
type UpdateBuilder ¶
type UpdateBuilder struct { Cond // contains filtered or unexported fields }
UpdateBuilder is a builder to build UPDATE.
func NewUpdateBuilder ¶
func NewUpdateBuilder() *UpdateBuilder
NewUpdateBuilder creates a new UPDATE builder.
func (*UpdateBuilder) Add ¶
func (ub *UpdateBuilder) Add(field string, value interface{}) string
Add represents SET "field = field + value" in UPDATE.
func (*UpdateBuilder) Asc ¶
func (ub *UpdateBuilder) Asc() *UpdateBuilder
Asc sets order of ORDER BY to ASC.
func (*UpdateBuilder) Assign ¶
func (ub *UpdateBuilder) Assign(field string, value interface{}) string
Assign represents SET "field = value" in UPDATE.
func (*UpdateBuilder) Build ¶
func (ub *UpdateBuilder) Build(initialArg ...interface{}) (sql string, args []interface{})
BuildWithFlavor returns compiled UPDATE string and args with flavor and initial args. They can be used in `DB#Query` of package `database/sql` directly.
func (*UpdateBuilder) Decr ¶
func (ub *UpdateBuilder) Decr(field string) string
Decr represents SET "field = field - 1" in UPDATE.
func (*UpdateBuilder) Desc ¶
func (ub *UpdateBuilder) Desc() *UpdateBuilder
Desc sets order of ORDER BY to DESC.
func (*UpdateBuilder) Div ¶
func (ub *UpdateBuilder) Div(field string, value interface{}) string
Div represents SET "field = field / value" in UPDATE.
func (*UpdateBuilder) Incr ¶
func (ub *UpdateBuilder) Incr(field string) string
Incr represents SET "field = field + 1" in UPDATE.
func (*UpdateBuilder) Limit ¶
func (ub *UpdateBuilder) Limit(limit int) *UpdateBuilder
Limit sets the LIMIT in UPDATE.
func (*UpdateBuilder) Mul ¶
func (ub *UpdateBuilder) Mul(field string, value interface{}) string
Mul represents SET "field = field * value" in UPDATE.
func (*UpdateBuilder) OrderBy ¶
func (ub *UpdateBuilder) OrderBy(col ...string) *UpdateBuilder
OrderBy sets columns of ORDER BY in UPDATE.
func (*UpdateBuilder) Set ¶
func (ub *UpdateBuilder) Set(assignment ...string) *UpdateBuilder
Set sets the assignments in SET.
func (*UpdateBuilder) SetMore ¶
func (ub *UpdateBuilder) SetMore(assignment ...string) *UpdateBuilder
SetMore appends the assignments in SET.
func (*UpdateBuilder) Sub ¶
func (ub *UpdateBuilder) Sub(field string, value interface{}) string
Sub represents SET "field = field - value" in UPDATE.
func (*UpdateBuilder) Update ¶
func (ub *UpdateBuilder) Update(table string) *UpdateBuilder
Update sets table name in UPDATE.
func (*UpdateBuilder) Where ¶
func (ub *UpdateBuilder) Where(andExpr ...string) *UpdateBuilder
Where sets expressions of WHERE in UPDATE.