Documentation ¶
Overview ¶
Package squirrel provides a fluent SQL generator.
See https://github.com/lann/squirrel for examples.
Index ¶
- Variables
- func Alias(expr Sqlizer, alias string) aliasExpr
- func DebugSqlizer(s Sqlizer) string
- func Expr(sql string, args ...interface{}) expr
- func Placeholders(count int) string
- type And
- type CaseBuilder
- type DeleteBuilder
- func (b DeleteBuilder) Condition() WhereConditions
- func (b DeleteBuilder) Eq(column string, arg interface{}) WhereConditions
- func (b DeleteBuilder) Expr(sql string, args ...interface{}) WhereConditions
- func (b DeleteBuilder) From(from string) DeleteCondition
- func (b DeleteBuilder) GroupBy(groupBys ...string) WhereConditions
- func (b DeleteBuilder) Gt(column string, arg interface{}) WhereConditions
- func (b DeleteBuilder) GtOrEq(column string, arg interface{}) WhereConditions
- func (b DeleteBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
- func (b DeleteBuilder) Limit(limit int) WhereConditions
- func (b DeleteBuilder) Lt(column string, arg interface{}) WhereConditions
- func (b DeleteBuilder) LtOrEq(column string, arg interface{}) WhereConditions
- func (b DeleteBuilder) NotEq(column string, arg interface{}) WhereConditions
- func (b DeleteBuilder) Offset(offset int) WhereConditions
- func (b DeleteBuilder) OrderBy(orderBys ...string) WhereConditions
- func (b DeleteBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
- func (b DeleteBuilder) Prefix(sql string, args ...interface{}) DeleteCondition
- func (b DeleteBuilder) Suffix(sql string, args ...interface{}) WhereConditions
- func (b DeleteBuilder) ToSql() (string, []interface{})
- func (b DeleteBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
- type DeleteCondition
- type Eq
- type Gt
- type GtOrEq
- type InsertBuilder
- func (b InsertBuilder) Columns(columns ...string) InsertCondition
- func (b InsertBuilder) Into(from string) InsertCondition
- func (b InsertBuilder) Options(options ...string) InsertCondition
- func (b InsertBuilder) PlaceholderFormat(f PlaceholderFormat) InsertCondition
- func (b InsertBuilder) Prefix(sql string, args ...interface{}) InsertCondition
- func (b InsertBuilder) Select(sb SelectCondition) InsertCondition
- func (b InsertBuilder) SetMap(clauses map[string]interface{}) InsertCondition
- func (b InsertBuilder) Suffix(sql string, args ...interface{}) InsertCondition
- func (b InsertBuilder) ToSql() (string, []interface{})
- func (b InsertBuilder) Values(values ...interface{}) InsertCondition
- type InsertCondition
- type JoinBuilder
- func (b JoinBuilder) Condition() WhereConditions
- func (b JoinBuilder) Eq(column string, arg interface{}) WhereConditions
- func (b JoinBuilder) Expr(sql string, args ...interface{}) WhereConditions
- func (b JoinBuilder) GroupBy(groupBys ...string) WhereConditions
- func (b JoinBuilder) Gt(column string, arg interface{}) WhereConditions
- func (b JoinBuilder) GtOrEq(column string, arg interface{}) WhereConditions
- func (b JoinBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
- func (b JoinBuilder) Join(join string, rest ...interface{}) JoinCondition
- func (b JoinBuilder) JoinClause(pred interface{}, args ...interface{}) JoinCondition
- func (b JoinBuilder) LeftJoin(join string, rest ...interface{}) JoinCondition
- func (b JoinBuilder) Limit(limit int) WhereConditions
- func (b JoinBuilder) Lt(column string, arg interface{}) WhereConditions
- func (b JoinBuilder) LtOrEq(column string, arg interface{}) WhereConditions
- func (b JoinBuilder) NotEq(column string, arg interface{}) WhereConditions
- func (b JoinBuilder) Offset(offset int) WhereConditions
- func (b JoinBuilder) Or(pred ...interface{}) WhereConditions
- func (b JoinBuilder) OrderBy(orderBys ...string) WhereConditions
- func (b JoinBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
- func (b JoinBuilder) RightJoin(join string, rest ...interface{}) JoinCondition
- func (b JoinBuilder) Suffix(sql string, args ...interface{}) WhereConditions
- func (b JoinBuilder) ToSql() (string, []interface{})
- func (b JoinBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
- type JoinCondition
- type Lt
- type LtOrEq
- type NotEq
- type Or
- type PlaceholderFormat
- type SelectBuilder
- func (b SelectBuilder) Column(column interface{}, args ...interface{}) SelectCondition
- func (b SelectBuilder) Columns(columns ...string) SelectCondition
- func (b SelectBuilder) Condition() WhereConditions
- func (b SelectBuilder) Distinct() SelectCondition
- func (b SelectBuilder) Eq(column string, arg interface{}) WhereConditions
- func (b SelectBuilder) Expr(sql string, args ...interface{}) WhereConditions
- func (b SelectBuilder) From(from string) SelectCondition
- func (b SelectBuilder) FromSelect(from SelectCondition, alias string) SelectCondition
- func (b SelectBuilder) GroupBy(groupBys ...string) WhereConditions
- func (b SelectBuilder) Gt(column string, arg interface{}) WhereConditions
- func (b SelectBuilder) GtOrEq(column string, arg interface{}) WhereConditions
- func (b SelectBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
- func (b SelectBuilder) Join(join string, rest ...interface{}) JoinCondition
- func (b SelectBuilder) JoinClause(pred interface{}, args ...interface{}) JoinCondition
- func (b SelectBuilder) LeftJoin(join string, rest ...interface{}) JoinCondition
- func (b SelectBuilder) Limit(limit int) WhereConditions
- func (b SelectBuilder) Lt(column string, arg interface{}) WhereConditions
- func (b SelectBuilder) LtOrEq(column string, arg interface{}) WhereConditions
- func (b SelectBuilder) NotEq(column string, arg interface{}) WhereConditions
- func (b SelectBuilder) Offset(offset int) WhereConditions
- func (b SelectBuilder) Options(options ...string) SelectCondition
- func (b SelectBuilder) OrderBy(orderBys ...string) WhereConditions
- func (b SelectBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
- func (b SelectBuilder) Prefix(sql string, args ...interface{}) SelectCondition
- func (b SelectBuilder) RightJoin(join string, rest ...interface{}) JoinCondition
- func (b SelectBuilder) Suffix(sql string, args ...interface{}) WhereConditions
- func (b SelectBuilder) ToSql() (string, []interface{})
- func (b SelectBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
- type SelectCondition
- type Sqlizer
- type StatementBuilderType
- func (b StatementBuilderType) Condition() WhereConditions
- func (b StatementBuilderType) Count(columns string) SelectCondition
- func (b StatementBuilderType) Delete(from string) DeleteCondition
- func (b StatementBuilderType) Insert(into string) InsertCondition
- func (b StatementBuilderType) Join(join string, rest ...interface{}) JoinCondition
- func (b StatementBuilderType) JoinClause(pred interface{}, args ...interface{}) JoinCondition
- func (b StatementBuilderType) LeftJoin(join string, rest ...interface{}) JoinCondition
- func (b StatementBuilderType) PlaceholderFormat(f PlaceholderFormat) StatementBuilderType
- func (b StatementBuilderType) RightJoin(join string, rest ...interface{}) JoinCondition
- func (b StatementBuilderType) Select(columns ...string) SelectCondition
- func (b StatementBuilderType) Update(table string) UpdateCondition
- func (b StatementBuilderType) Where(pred interface{}, args ...interface{}) WhereConditions
- type UpdateBuilder
- func (b UpdateBuilder) Condition() WhereConditions
- func (b UpdateBuilder) DecrBy(column string, num int) UpdateCondition
- func (b UpdateBuilder) Eq(column string, arg interface{}) WhereConditions
- func (b UpdateBuilder) Expr(sql string, args ...interface{}) WhereConditions
- func (b UpdateBuilder) GroupBy(groupBys ...string) WhereConditions
- func (b UpdateBuilder) Gt(column string, arg interface{}) WhereConditions
- func (b UpdateBuilder) GtOrEq(column string, arg interface{}) WhereConditions
- func (b UpdateBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
- func (b UpdateBuilder) IncrBy(column string, num int) UpdateCondition
- func (b UpdateBuilder) Limit(limit int) WhereConditions
- func (b UpdateBuilder) Lt(column string, arg interface{}) WhereConditions
- func (b UpdateBuilder) LtOrEq(column string, arg interface{}) WhereConditions
- func (b UpdateBuilder) NotEq(column string, arg interface{}) WhereConditions
- func (b UpdateBuilder) Offset(offset int) WhereConditions
- func (b UpdateBuilder) OrderBy(orderBys ...string) WhereConditions
- func (b UpdateBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
- func (b UpdateBuilder) Prefix(sql string, args ...interface{}) UpdateCondition
- func (b UpdateBuilder) Set(column string, value interface{}) UpdateCondition
- func (b UpdateBuilder) SetMap(clauses map[string]interface{}) UpdateCondition
- func (b UpdateBuilder) Suffix(sql string, args ...interface{}) WhereConditions
- func (b UpdateBuilder) Table(table string) UpdateCondition
- func (b UpdateBuilder) ToSql() (string, []interface{})
- func (b UpdateBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
- type UpdateCondition
- type WhereBuilder
- func (b WhereBuilder) Condition() WhereConditions
- func (b WhereBuilder) Eq(column string, arg interface{}) WhereConditions
- func (b WhereBuilder) Expr(sql string, args ...interface{}) WhereConditions
- func (b WhereBuilder) GroupBy(groupBys ...string) WhereConditions
- func (b WhereBuilder) Gt(column string, arg interface{}) WhereConditions
- func (b WhereBuilder) GtOrEq(column string, arg interface{}) WhereConditions
- func (b WhereBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
- func (b WhereBuilder) Limit(limit int) WhereConditions
- func (b WhereBuilder) Lt(column string, arg interface{}) WhereConditions
- func (b WhereBuilder) LtOrEq(column string, arg interface{}) WhereConditions
- func (b WhereBuilder) NotEq(column string, arg interface{}) WhereConditions
- func (b WhereBuilder) Offset(offset int) WhereConditions
- func (b WhereBuilder) Or(pred ...interface{}) WhereBuilder
- func (b WhereBuilder) OrderBy(orderBys ...string) WhereConditions
- func (b WhereBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
- func (b WhereBuilder) Suffix(sql string, args ...interface{}) WhereConditions
- func (b WhereBuilder) ToSql() (string, []interface{})
- func (b WhereBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
- type WhereConditions
Constants ¶
This section is empty.
Variables ¶
var ( // Question is a PlaceholderFormat instance that leaves placeholders as // question marks. Question = questionFormat{} // Dollar is a PlaceholderFormat instance that replaces placeholders with // dollar-prefixed positional placeholders (e.g. $1, $2, $3). Dollar = dollarFormat{} )
var StatementBuilder = StatementBuilderType(builder.EmptyBuilder).PlaceholderFormat(Question)
StatementBuilder is a parent builder for other builders, e.g. SelectBuilder.
Functions ¶
func Alias ¶
Alias allows to define alias for column in SelectBuilder. Useful when column is defined as complex expression like IF or CASE Ex:
.Column(Alias(caseStmt, "case_column"))
func DebugSqlizer ¶
DebugSqlizer calls ToSql on s and shows the approximate SQL to be executed
If ToSql returns an error, the result of this method will look like: "[ToSql error: %s]" or "[DebugSqlizer error: %s]"
IMPORTANT: As its name suggests, this function should only be used for debugging. While the string result *might* be valid SQL, this function does not try very hard to ensure it. Additionally, executing the output of this function with any untrusted user input is certainly insecure.
func Expr ¶
func Expr(sql string, args ...interface{}) expr
Expr builds value expressions for InsertBuilder and UpdateBuilder.
Ex:
.Values(Expr("FROM_UNIXTIME(?)", t))
func Placeholders ¶
Placeholders returns a string with count ? placeholders joined with commas.
Types ¶
type CaseBuilder ¶
CaseBuilder builds SQL CASE construct which could be used as parts of queries.
func (CaseBuilder) Else ¶
func (b CaseBuilder) Else(expr interface{}) CaseBuilder
What sets optional "ELSE ..." part for CASE construct
func (CaseBuilder) ToSql ¶
func (b CaseBuilder) ToSql() (string, []interface{})
ToSql builds the query into a SQL string and bound args.
func (CaseBuilder) When ¶
func (b CaseBuilder) When(when interface{}, then interface{}) CaseBuilder
When adds "WHEN ... THEN ..." part to CASE construct
type DeleteBuilder ¶
DeleteBuilder builds SQL DELETE statements.
func (DeleteBuilder) Eq ¶
func (b DeleteBuilder) Eq(column string, arg interface{}) WhereConditions
eq
func (DeleteBuilder) Expr ¶
func (b DeleteBuilder) Expr(sql string, args ...interface{}) WhereConditions
expr
func (DeleteBuilder) From ¶
func (b DeleteBuilder) From(from string) DeleteCondition
From sets the table to be deleted from.
func (DeleteBuilder) GroupBy ¶
func (b DeleteBuilder) GroupBy(groupBys ...string) WhereConditions
OrderBy adds ORDER BY expressions to the query.
func (DeleteBuilder) Gt ¶
func (b DeleteBuilder) Gt(column string, arg interface{}) WhereConditions
gt
func (DeleteBuilder) GtOrEq ¶
func (b DeleteBuilder) GtOrEq(column string, arg interface{}) WhereConditions
gtOrEq
func (DeleteBuilder) Having ¶
func (b DeleteBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
func (DeleteBuilder) Limit ¶
func (b DeleteBuilder) Limit(limit int) WhereConditions
Limit sets a LIMIT clause on the query.
func (DeleteBuilder) Lt ¶
func (b DeleteBuilder) Lt(column string, arg interface{}) WhereConditions
lt
func (DeleteBuilder) LtOrEq ¶
func (b DeleteBuilder) LtOrEq(column string, arg interface{}) WhereConditions
ltOrEq
func (DeleteBuilder) NotEq ¶
func (b DeleteBuilder) NotEq(column string, arg interface{}) WhereConditions
func (DeleteBuilder) Offset ¶
func (b DeleteBuilder) Offset(offset int) WhereConditions
Offset sets a OFFSET clause on the query.
func (DeleteBuilder) OrderBy ¶
func (b DeleteBuilder) OrderBy(orderBys ...string) WhereConditions
OrderBy adds ORDER BY expressions to the query.
func (DeleteBuilder) PlaceholderFormat ¶
func (b DeleteBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (DeleteBuilder) Prefix ¶
func (b DeleteBuilder) Prefix(sql string, args ...interface{}) DeleteCondition
Prefix adds an expression to the beginning of the query
func (DeleteBuilder) Suffix ¶
func (b DeleteBuilder) Suffix(sql string, args ...interface{}) WhereConditions
Suffix adds an expression to the end of the query
func (DeleteBuilder) ToSql ¶
func (b DeleteBuilder) ToSql() (string, []interface{})
ToSql builds the query into a SQL string and bound args.
func (DeleteBuilder) Where ¶
func (b DeleteBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
Where adds WHERE expressions to the query.
See SelectBuilder.Where for more information.
type DeleteCondition ¶
type DeleteCondition interface { Prefix(string, ...interface{}) DeleteCondition From(string) DeleteCondition WhereConditions }
func Delete ¶
func Delete(from string) DeleteCondition
Delete returns a new DeleteBuilder with the given table name.
See DeleteBuilder.Table.
type Eq ¶
type Eq map[string]interface{}
Eq is syntactic sugar for use with Where/Having/Set methods. Ex:
.Where(Eq{"id": 1})
type Gt ¶
type Gt Lt
Gt is syntactic sugar for use with Where/Having/Set methods. Ex:
.Where(Gt{"id": 1}) == "id > 1"
type GtOrEq ¶
type GtOrEq Lt
GtOrEq is syntactic sugar for use with Where/Having/Set methods. Ex:
.Where(GtOrEq{"id": 1}) == "id >= 1"
type InsertBuilder ¶
InsertBuilder builds SQL INSERT statements.
func (InsertBuilder) Columns ¶
func (b InsertBuilder) Columns(columns ...string) InsertCondition
Columns adds insert columns to the query.
func (InsertBuilder) Into ¶
func (b InsertBuilder) Into(from string) InsertCondition
Into sets the INTO clause of the query.
func (InsertBuilder) Options ¶
func (b InsertBuilder) Options(options ...string) InsertCondition
Options adds keyword options before the INTO clause of the query.
func (InsertBuilder) PlaceholderFormat ¶
func (b InsertBuilder) PlaceholderFormat(f PlaceholderFormat) InsertCondition
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (InsertBuilder) Prefix ¶
func (b InsertBuilder) Prefix(sql string, args ...interface{}) InsertCondition
Prefix adds an expression to the beginning of the query
func (InsertBuilder) Select ¶
func (b InsertBuilder) Select(sb SelectCondition) InsertCondition
Select set Select clause for insert query If Values and Select are used, then Select has higher priority
func (InsertBuilder) SetMap ¶
func (b InsertBuilder) SetMap(clauses map[string]interface{}) InsertCondition
SetMap set columns and values for insert builder from a map of column name and value note that it will reset all previous columns and values was set if any
func (InsertBuilder) Suffix ¶
func (b InsertBuilder) Suffix(sql string, args ...interface{}) InsertCondition
Suffix adds an expression to the end of the query
func (InsertBuilder) ToSql ¶
func (b InsertBuilder) ToSql() (string, []interface{})
ToSql builds the query into a SQL string and bound args.
func (InsertBuilder) Values ¶
func (b InsertBuilder) Values(values ...interface{}) InsertCondition
Values adds a single row's values to the query.
type InsertCondition ¶
type InsertCondition interface { ToSql() (string, []interface{}) PlaceholderFormat(PlaceholderFormat) InsertCondition Prefix(string, ...interface{}) InsertCondition Options(...string) InsertCondition Into(string) InsertCondition Columns(...string) InsertCondition Values(...interface{}) InsertCondition Suffix(string, ...interface{}) InsertCondition SetMap(map[string]interface{}) InsertCondition Select(SelectCondition) InsertCondition }
func Insert ¶
func Insert(into string) InsertCondition
Insert returns a new InsertBuilder with the given table name.
See InsertBuilder.Into.
type JoinBuilder ¶
JoinBuilder builds SQL SELECT statements.
func (JoinBuilder) Expr ¶
func (b JoinBuilder) Expr(sql string, args ...interface{}) WhereConditions
expr
func (JoinBuilder) GroupBy ¶
func (b JoinBuilder) GroupBy(groupBys ...string) WhereConditions
GroupBy adds GROUP BY expressions to the query.
func (JoinBuilder) GtOrEq ¶
func (b JoinBuilder) GtOrEq(column string, arg interface{}) WhereConditions
gtOrEq
func (JoinBuilder) Having ¶
func (b JoinBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
Having adds an expression to the HAVING clause of the query.
See Where.
func (JoinBuilder) Join ¶
func (b JoinBuilder) Join(join string, rest ...interface{}) JoinCondition
Join adds a JOIN clause to the query.
func (JoinBuilder) JoinClause ¶
func (b JoinBuilder) JoinClause(pred interface{}, args ...interface{}) JoinCondition
JoinClause adds a join clause to the query.
func (JoinBuilder) LeftJoin ¶
func (b JoinBuilder) LeftJoin(join string, rest ...interface{}) JoinCondition
LeftJoin adds a LEFT JOIN clause to the query.
func (JoinBuilder) Limit ¶
func (b JoinBuilder) Limit(limit int) WhereConditions
Limit sets a LIMIT clause on the query.
func (JoinBuilder) LtOrEq ¶
func (b JoinBuilder) LtOrEq(column string, arg interface{}) WhereConditions
ltOrEq
func (JoinBuilder) NotEq ¶
func (b JoinBuilder) NotEq(column string, arg interface{}) WhereConditions
func (JoinBuilder) Offset ¶
func (b JoinBuilder) Offset(offset int) WhereConditions
Offset sets a OFFSET clause on the query.
func (JoinBuilder) OrderBy ¶
func (b JoinBuilder) OrderBy(orderBys ...string) WhereConditions
OrderBy adds ORDER BY expressions to the query.
func (JoinBuilder) PlaceholderFormat ¶
func (b JoinBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (JoinBuilder) RightJoin ¶
func (b JoinBuilder) RightJoin(join string, rest ...interface{}) JoinCondition
RightJoin adds a RIGHT JOIN clause to the query.
func (JoinBuilder) Suffix ¶
func (b JoinBuilder) Suffix(sql string, args ...interface{}) WhereConditions
Suffix adds an expression to the end of the query
func (JoinBuilder) ToSql ¶
func (b JoinBuilder) ToSql() (string, []interface{})
ToSql builds the query into a SQL string and bound args.
func (JoinBuilder) Where ¶
func (b JoinBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
Where adds an expression to the WHERE clause of the query.
Expressions are ANDed together in the generated SQL.
Where accepts several types for its pred argument:
nil OR "" - ignored.
string - SQL expression. If the expression has SQL placeholders then a set of arguments must be passed as well, one for each placeholder.
map[string]interface{} OR Eq - map of SQL expressions to values. Each key is transformed into an expression like "<key> = ?", with the corresponding value bound to the placeholder. If the value is nil, the expression will be "<key> IS NULL". If the value is an array or slice, the expression will be "<key> IN (?,?,...)", with one placeholder for each item in the value. These expressions are ANDed together.
Where will panic if pred isn't any of the above types.
type JoinCondition ¶
type JoinCondition interface { JoinClause(interface{}, ...interface{}) JoinCondition Join(string, ...interface{}) JoinCondition LeftJoin(string, ...interface{}) JoinCondition RightJoin(string, ...interface{}) JoinCondition WhereConditions }
func JoinClause ¶
func JoinClause(pred interface{}, args ...interface{}) JoinCondition
func LeftJoin ¶
func LeftJoin(join string, rest ...interface{}) JoinCondition
func RightJoin ¶
func RightJoin(join string, rest ...interface{}) JoinCondition
type Lt ¶
type Lt map[string]interface{}
Lt is syntactic sugar for use with Where/Having/Set methods. Ex:
.Where(Lt{"id": 1})
type LtOrEq ¶
type LtOrEq Lt
LtOrEq is syntactic sugar for use with Where/Having/Set methods. Ex:
.Where(LtOrEq{"id": 1}) == "id <= 1"
type NotEq ¶
type NotEq Eq
NotEq is syntactic sugar for use with Where/Having/Set methods. Ex:
.Where(NotEq{"id": 1}) == "id <> 1"
type PlaceholderFormat ¶
PlaceholderFormat is the interface that wraps the ReplacePlaceholders method.
ReplacePlaceholders takes a SQL statement and replaces each question mark placeholder with a (possibly different) SQL placeholder.
type SelectBuilder ¶
SelectBuilder builds SQL SELECT statements.
func (SelectBuilder) Column ¶
func (b SelectBuilder) Column(column interface{}, args ...interface{}) SelectCondition
Column adds a result column to the query. Unlike Columns, Column accepts args which will be bound to placeholders in the columns string, for example:
Column("IF(col IN ("+squirrel.Placeholders(3)+"), 1, 0) as col", 1, 2, 3)
func (SelectBuilder) Columns ¶
func (b SelectBuilder) Columns(columns ...string) SelectCondition
Columns adds result columns to the query.
func (SelectBuilder) Distinct ¶
func (b SelectBuilder) Distinct() SelectCondition
Distinct adds a DISTINCT clause to the query.
func (SelectBuilder) Eq ¶
func (b SelectBuilder) Eq(column string, arg interface{}) WhereConditions
eq
func (SelectBuilder) Expr ¶
func (b SelectBuilder) Expr(sql string, args ...interface{}) WhereConditions
expr
func (SelectBuilder) From ¶
func (b SelectBuilder) From(from string) SelectCondition
From sets the FROM clause of the query.
func (SelectBuilder) FromSelect ¶
func (b SelectBuilder) FromSelect(from SelectCondition, alias string) SelectCondition
FromSelect sets a subquery into the FROM clause of the query.
func (SelectBuilder) GroupBy ¶
func (b SelectBuilder) GroupBy(groupBys ...string) WhereConditions
GroupBy adds GROUP BY expressions to the query.
func (SelectBuilder) Gt ¶
func (b SelectBuilder) Gt(column string, arg interface{}) WhereConditions
gt
func (SelectBuilder) GtOrEq ¶
func (b SelectBuilder) GtOrEq(column string, arg interface{}) WhereConditions
gtOrEq
func (SelectBuilder) Having ¶
func (b SelectBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
Having adds an expression to the HAVING clause of the query.
See Where.
func (SelectBuilder) Join ¶
func (b SelectBuilder) Join(join string, rest ...interface{}) JoinCondition
Join adds a JOIN clause to the query.
func (SelectBuilder) JoinClause ¶
func (b SelectBuilder) JoinClause(pred interface{}, args ...interface{}) JoinCondition
JoinClause adds a join clause to the query.
func (SelectBuilder) LeftJoin ¶
func (b SelectBuilder) LeftJoin(join string, rest ...interface{}) JoinCondition
LeftJoin adds a LEFT JOIN clause to the query.
func (SelectBuilder) Limit ¶
func (b SelectBuilder) Limit(limit int) WhereConditions
Limit sets a LIMIT clause on the query.
func (SelectBuilder) Lt ¶
func (b SelectBuilder) Lt(column string, arg interface{}) WhereConditions
lt
func (SelectBuilder) LtOrEq ¶
func (b SelectBuilder) LtOrEq(column string, arg interface{}) WhereConditions
ltOrEq
func (SelectBuilder) NotEq ¶
func (b SelectBuilder) NotEq(column string, arg interface{}) WhereConditions
func (SelectBuilder) Offset ¶
func (b SelectBuilder) Offset(offset int) WhereConditions
Offset sets a OFFSET clause on the query.
func (SelectBuilder) Options ¶
func (b SelectBuilder) Options(options ...string) SelectCondition
Options adds select option to the query
func (SelectBuilder) OrderBy ¶
func (b SelectBuilder) OrderBy(orderBys ...string) WhereConditions
OrderBy adds ORDER BY expressions to the query.
func (SelectBuilder) PlaceholderFormat ¶
func (b SelectBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (SelectBuilder) Prefix ¶
func (b SelectBuilder) Prefix(sql string, args ...interface{}) SelectCondition
Prefix adds an expression to the beginning of the query
func (SelectBuilder) RightJoin ¶
func (b SelectBuilder) RightJoin(join string, rest ...interface{}) JoinCondition
RightJoin adds a RIGHT JOIN clause to the query.
func (SelectBuilder) Suffix ¶
func (b SelectBuilder) Suffix(sql string, args ...interface{}) WhereConditions
Suffix adds an expression to the end of the query
func (SelectBuilder) ToSql ¶
func (b SelectBuilder) ToSql() (string, []interface{})
ToSql builds the query into a SQL string and bound args.
func (SelectBuilder) Where ¶
func (b SelectBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
Where adds an expression to the WHERE clause of the query.
Expressions are ANDed together in the generated SQL.
Where accepts several types for its pred argument:
nil OR "" - ignored.
string - SQL expression. If the expression has SQL placeholders then a set of arguments must be passed as well, one for each placeholder.
map[string]interface{} OR Eq - map of SQL expressions to values. Each key is transformed into an expression like "<key> = ?", with the corresponding value bound to the placeholder. If the value is nil, the expression will be "<key> IS NULL". If the value is an array or slice, the expression will be "<key> IN (?,?,...)", with one placeholder for each item in the value. These expressions are ANDed together.
Where will panic if pred isn't any of the above types.
type SelectCondition ¶
type SelectCondition interface { Prefix(string, ...interface{}) SelectCondition Distinct() SelectCondition Options(...string) SelectCondition Columns(...string) SelectCondition Column(interface{}, ...interface{}) SelectCondition From(string) SelectCondition FromSelect(SelectCondition, string) SelectCondition JoinCondition }
func Select ¶
func Select(columns ...string) SelectCondition
Select returns a new SelectBuilder, optionally setting some result columns.
See SelectBuilder.Columns.
type Sqlizer ¶
type Sqlizer interface {
ToSql() (string, []interface{})
}
Sqlizer is the interface that wraps the ToSql method.
ToSql returns a SQL representation of the Sqlizer, along with a slice of args as passed to e.g. database/sql.Exec. It can also return an error.
type StatementBuilderType ¶
StatementBuilderType is the type of StatementBuilder.
func (StatementBuilderType) Condition ¶
func (b StatementBuilderType) Condition() WhereConditions
func (StatementBuilderType) Count ¶
func (b StatementBuilderType) Count(columns string) SelectCondition
func (StatementBuilderType) Delete ¶
func (b StatementBuilderType) Delete(from string) DeleteCondition
Delete returns a DeleteBuilder for this StatementBuilderType.
func (StatementBuilderType) Insert ¶
func (b StatementBuilderType) Insert(into string) InsertCondition
Insert returns a InsertBuilder for this StatementBuilderType.
func (StatementBuilderType) Join ¶
func (b StatementBuilderType) Join(join string, rest ...interface{}) JoinCondition
func (StatementBuilderType) JoinClause ¶
func (b StatementBuilderType) JoinClause(pred interface{}, args ...interface{}) JoinCondition
func (StatementBuilderType) LeftJoin ¶
func (b StatementBuilderType) LeftJoin(join string, rest ...interface{}) JoinCondition
func (StatementBuilderType) PlaceholderFormat ¶
func (b StatementBuilderType) PlaceholderFormat(f PlaceholderFormat) StatementBuilderType
PlaceholderFormat sets the PlaceholderFormat field for any child builders.
func (StatementBuilderType) RightJoin ¶
func (b StatementBuilderType) RightJoin(join string, rest ...interface{}) JoinCondition
func (StatementBuilderType) Select ¶
func (b StatementBuilderType) Select(columns ...string) SelectCondition
Select returns a SelectBuilder for this StatementBuilderType.
func (StatementBuilderType) Update ¶
func (b StatementBuilderType) Update(table string) UpdateCondition
Update returns a UpdateBuilder for this StatementBuilderType.
func (StatementBuilderType) Where ¶
func (b StatementBuilderType) Where(pred interface{}, args ...interface{}) WhereConditions
type UpdateBuilder ¶
UpdateBuilder builds SQL UPDATE statements.
func (UpdateBuilder) DecrBy ¶
func (b UpdateBuilder) DecrBy(column string, num int) UpdateCondition
func (UpdateBuilder) Eq ¶
func (b UpdateBuilder) Eq(column string, arg interface{}) WhereConditions
eq
func (UpdateBuilder) Expr ¶
func (b UpdateBuilder) Expr(sql string, args ...interface{}) WhereConditions
expr
func (UpdateBuilder) GroupBy ¶
func (b UpdateBuilder) GroupBy(groupBys ...string) WhereConditions
GroupBy adds GROUP BY expressions to the query.
func (UpdateBuilder) Gt ¶
func (b UpdateBuilder) Gt(column string, arg interface{}) WhereConditions
gt
func (UpdateBuilder) GtOrEq ¶
func (b UpdateBuilder) GtOrEq(column string, arg interface{}) WhereConditions
gtOrEq
func (UpdateBuilder) Having ¶
func (b UpdateBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
Having adds an expression to the HAVING clause of the query.
See Where.
func (UpdateBuilder) IncrBy ¶
func (b UpdateBuilder) IncrBy(column string, num int) UpdateCondition
func (UpdateBuilder) Limit ¶
func (b UpdateBuilder) Limit(limit int) WhereConditions
Limit sets a LIMIT clause on the update.
func (UpdateBuilder) Lt ¶
func (b UpdateBuilder) Lt(column string, arg interface{}) WhereConditions
lt
func (UpdateBuilder) LtOrEq ¶
func (b UpdateBuilder) LtOrEq(column string, arg interface{}) WhereConditions
ltOrEq
func (UpdateBuilder) NotEq ¶
func (b UpdateBuilder) NotEq(column string, arg interface{}) WhereConditions
func (UpdateBuilder) Offset ¶
func (b UpdateBuilder) Offset(offset int) WhereConditions
Offset sets a OFFSET clause on the query.
func (UpdateBuilder) OrderBy ¶
func (b UpdateBuilder) OrderBy(orderBys ...string) WhereConditions
OrderBy adds ORDER BY expressions to the query.
func (UpdateBuilder) PlaceholderFormat ¶
func (b UpdateBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (UpdateBuilder) Prefix ¶
func (b UpdateBuilder) Prefix(sql string, args ...interface{}) UpdateCondition
Prefix adds an expression to the beginning of the query
func (UpdateBuilder) Set ¶
func (b UpdateBuilder) Set(column string, value interface{}) UpdateCondition
Set adds SET clauses to the query.
func (UpdateBuilder) SetMap ¶
func (b UpdateBuilder) SetMap(clauses map[string]interface{}) UpdateCondition
SetMap is a convenience method which calls .Set for each key/value pair in clauses.
func (UpdateBuilder) Suffix ¶
func (b UpdateBuilder) Suffix(sql string, args ...interface{}) WhereConditions
Suffix adds an expression to the end of the query
func (UpdateBuilder) Table ¶
func (b UpdateBuilder) Table(table string) UpdateCondition
Table sets the table to be updated.
func (UpdateBuilder) ToSql ¶
func (b UpdateBuilder) ToSql() (string, []interface{})
ToSql builds the query into a SQL string and bound args.
func (UpdateBuilder) Where ¶
func (b UpdateBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
Where adds WHERE expressions to the query.
See SelectBuilder.Where for more information.
type UpdateCondition ¶
type UpdateCondition interface { Prefix(string, ...interface{}) UpdateCondition Table(string) UpdateCondition Set(string, interface{}) UpdateCondition IncrBy(string, int) UpdateCondition DecrBy(string, int) UpdateCondition SetMap(map[string]interface{}) UpdateCondition WhereConditions }
func Update ¶
func Update(table string) UpdateCondition
Update returns a new UpdateBuilder with the given table name.
See UpdateBuilder.Table.
type WhereBuilder ¶
WhereBuilder builds SQL SELECT statements.
func (WhereBuilder) Eq ¶
func (b WhereBuilder) Eq(column string, arg interface{}) WhereConditions
eq
func (WhereBuilder) Expr ¶
func (b WhereBuilder) Expr(sql string, args ...interface{}) WhereConditions
expr
func (WhereBuilder) GroupBy ¶
func (b WhereBuilder) GroupBy(groupBys ...string) WhereConditions
GroupBy adds GROUP BY expressions to the query.
func (WhereBuilder) Gt ¶
func (b WhereBuilder) Gt(column string, arg interface{}) WhereConditions
gt
func (WhereBuilder) GtOrEq ¶
func (b WhereBuilder) GtOrEq(column string, arg interface{}) WhereConditions
gtOrEq
func (WhereBuilder) Having ¶
func (b WhereBuilder) Having(pred interface{}, rest ...interface{}) WhereConditions
Having adds an expression to the HAVING clause of the query.
See Where.
func (WhereBuilder) Limit ¶
func (b WhereBuilder) Limit(limit int) WhereConditions
Limit sets a LIMIT clause on the query.
func (WhereBuilder) Lt ¶
func (b WhereBuilder) Lt(column string, arg interface{}) WhereConditions
lt
func (WhereBuilder) LtOrEq ¶
func (b WhereBuilder) LtOrEq(column string, arg interface{}) WhereConditions
ltOrEq
func (WhereBuilder) NotEq ¶
func (b WhereBuilder) NotEq(column string, arg interface{}) WhereConditions
func (WhereBuilder) Offset ¶
func (b WhereBuilder) Offset(offset int) WhereConditions
Offset sets a OFFSET clause on the query.
func (WhereBuilder) OrderBy ¶
func (b WhereBuilder) OrderBy(orderBys ...string) WhereConditions
OrderBy adds ORDER BY expressions to the query.
func (WhereBuilder) PlaceholderFormat ¶
func (b WhereBuilder) PlaceholderFormat(f PlaceholderFormat) WhereConditions
PlaceholderFormat sets PlaceholderFormat (e.g. Question or Dollar) for the query.
func (WhereBuilder) Suffix ¶
func (b WhereBuilder) Suffix(sql string, args ...interface{}) WhereConditions
Suffix adds an expression to the end of the query
func (WhereBuilder) ToSql ¶
func (b WhereBuilder) ToSql() (string, []interface{})
ToSql builds the query into a SQL string and bound args.
func (WhereBuilder) Where ¶
func (b WhereBuilder) Where(pred interface{}, args ...interface{}) WhereConditions
Where adds an expression to the WHERE clause of the query.
Expressions are ANDed together in the generated SQL.
Where accepts several types for its pred argument:
nil OR "" - ignored.
string - SQL expression. If the expression has SQL placeholders then a set of arguments must be passed as well, one for each placeholder.
map[string]interface{} OR Eq - map of SQL expressions to values. Each key is transformed into an expression like "<key> = ?", with the corresponding value bound to the placeholder. If the value is nil, the expression will be "<key> IS NULL". If the value is an array or slice, the expression will be "<key> IN (?,?,...)", with one placeholder for each item in the value. These expressions are ANDed together.
Where will panic if pred isn't any of the above types.
type WhereConditions ¶
type WhereConditions interface { ToSql() (string, []interface{}) PlaceholderFormat(PlaceholderFormat) WhereConditions Where(interface{}, ...interface{}) WhereConditions Condition() WhereConditions Expr(string, ...interface{}) WhereConditions Eq(string, interface{}) WhereConditions NotEq(string, interface{}) WhereConditions Gt(string, interface{}) WhereConditions GtOrEq(string, interface{}) WhereConditions Lt(string, interface{}) WhereConditions LtOrEq(string, interface{}) WhereConditions OrderBy(...string) WhereConditions GroupBy(...string) WhereConditions Having(interface{}, ...interface{}) WhereConditions Limit(int) WhereConditions Offset(int) WhereConditions Suffix(string, ...interface{}) WhereConditions }
func Condition ¶
func Condition() WhereConditions