Documentation ¶
Index ¶
- Constants
- Variables
- func Interpolate(sql string, vals []interface{}) (string, []interface{}, error)
- func NewDatSQLErr(err error) (string, []interface{}, error)
- func NewDatSQLError(msg string) (string, []interface{}, error)
- func NewError(msg string) error
- func ParseDir(dir string, version string) error
- func ParseSprocName(s string) string
- func PartitionKV(r io.Reader, prefix string, assignment string) ([]map[string]string, error)
- func SQLMapFromFile(filename string) (map[string]string, error)
- func SQLMapFromReader(r io.Reader) (map[string]string, error)
- func SQLMapFromString(s string) (map[string]string, error)
- func SQLSliceFromFile(filename string) ([]string, error)
- func SQLSliceFromString(s string) ([]string, error)
- type Builder
- type CallBuilder
- type DeleteBuilder
- func (b *DeleteBuilder) CanJSON() bool
- func (b *DeleteBuilder) Interpolate() (string, []interface{}, error)
- func (b *DeleteBuilder) IsInterpolated() bool
- func (b *DeleteBuilder) Returning(columns ...string) *DeleteBuilder
- func (b *DeleteBuilder) Scope(sql string, args ...interface{}) *DeleteBuilder
- func (b *DeleteBuilder) ScopeMap(mapScope *MapScope, m M) *DeleteBuilder
- func (b *DeleteBuilder) SetIsInterpolated(enable bool) *DeleteBuilder
- func (b *DeleteBuilder) ToSQL() (string, []interface{}, error)
- func (b *DeleteBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *DeleteBuilder
- type Eq
- type Error
- type Execer
- type Expression
- type Expressioner
- type InsectBuilder
- func (b *InsectBuilder) Blacklist(columns ...string) *InsectBuilder
- func (b *InsectBuilder) CanJSON() bool
- func (b *InsectBuilder) Columns(columns ...string) *InsectBuilder
- func (b *InsectBuilder) Interpolate() (string, []interface{}, error)
- func (b *InsectBuilder) IsInterpolated() bool
- func (b *InsectBuilder) Record(record interface{}) *InsectBuilder
- func (b *InsectBuilder) Returning(columns ...string) *InsectBuilder
- func (b *InsectBuilder) SetIsInterpolated(enable bool) *InsectBuilder
- func (b *InsectBuilder) ToSQL() (string, []interface{}, error)
- func (b *InsectBuilder) Values(vals ...interface{}) *InsectBuilder
- func (b *InsectBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *InsectBuilder
- func (b *InsectBuilder) Whitelist(columns ...string) *InsectBuilder
- type InsertBuilder
- func (b *InsertBuilder) Blacklist(columns ...string) *InsertBuilder
- func (b *InsertBuilder) CanJSON() bool
- func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder
- func (b *InsertBuilder) Interpolate() (string, []interface{}, error)
- func (b *InsertBuilder) IsInterpolated() bool
- func (b *InsertBuilder) OnConflictColumns(columns ...string) *InsertBuilder
- func (b *InsertBuilder) OnConflictConstraint(constraint string) *InsertBuilder
- func (b *InsertBuilder) OnConflictWhere(indexPredicate string, columns ...string) *InsertBuilder
- func (b *InsertBuilder) Pair(column string, value interface{}) *InsertBuilder
- func (b *InsertBuilder) Record(record interface{}) *InsertBuilder
- func (b *InsertBuilder) Returning(columns ...string) *InsertBuilder
- func (b *InsertBuilder) Set(column string, value interface{}) *InsertBuilder
- func (b *InsertBuilder) SetExcluded(columns ...string) *InsertBuilder
- func (b *InsertBuilder) SetIsInterpolated(enable bool) *InsertBuilder
- func (b *InsertBuilder) SetMap(clauses map[string]interface{}) *InsertBuilder
- func (b *InsertBuilder) ToSQL() (string, []interface{}, error)
- func (b *InsertBuilder) Values(vals ...interface{}) *InsertBuilder
- func (b *InsertBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *InsertBuilder
- func (b *InsertBuilder) Whitelist(columns ...string) *InsertBuilder
- type Interpolator
- type JSON
- type JSQLBuilder
- func (b *JSQLBuilder) CanJSON() bool
- func (b *JSQLBuilder) Interpolate() (string, []interface{}, error)
- func (b *JSQLBuilder) IsInterpolated() bool
- func (b *JSQLBuilder) Many(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
- func (b *JSQLBuilder) One(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
- func (b *JSQLBuilder) Scalar(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
- func (b *JSQLBuilder) SetIsInterpolated(enable bool) *JSQLBuilder
- func (b *JSQLBuilder) ToSQL() (string, []interface{}, error)
- func (b *JSQLBuilder) Union(sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
- func (b *JSQLBuilder) Vector(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
- type M
- type MapScope
- type NullBool
- type NullFloat64
- type NullInt64
- type NullString
- type NullTime
- type RawBuilder
- type Result
- type SQLDialect
- type Scope
- type ScopeFunc
- type SelectBuilder
- func (b *SelectBuilder) CanJSON() bool
- func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder
- func (b *SelectBuilder) Distinct() *SelectBuilder
- func (b *SelectBuilder) DistinctOn(columns ...string) *SelectBuilder
- func (b *SelectBuilder) For(options ...string) *SelectBuilder
- func (b *SelectBuilder) From(fromStr string, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) FullOuterJoin(joinStr string, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) GroupBy(group string) *SelectBuilder
- func (b *SelectBuilder) Having(whereSQLOrMap interface{}, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) Interpolate() (string, []interface{}, error)
- func (b *SelectBuilder) IsInterpolated() bool
- func (b *SelectBuilder) Join(joinStr string, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) LeftJoin(joinStr string, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) Limit(limit uint64) *SelectBuilder
- func (b *SelectBuilder) Offset(offset uint64) *SelectBuilder
- func (b *SelectBuilder) OrderBy(whereSQLOrMap interface{}, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) Paginate(page, perPage uint64) *SelectBuilder
- func (b *SelectBuilder) RightJoin(joinStr string, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) Scope(sql string, args ...interface{}) *SelectBuilder
- func (b *SelectBuilder) ScopeMap(mapScope *MapScope, m M) *SelectBuilder
- func (b *SelectBuilder) SetIsInterpolated(enable bool) *SelectBuilder
- func (b *SelectBuilder) ToSQL() (string, []interface{}, error)
- func (b *SelectBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *SelectBuilder
- type SelectDocBuilder
- func (b *SelectDocBuilder) CanJSON() bool
- func (b *SelectDocBuilder) Columns(columns ...string) *SelectDocBuilder
- func (b *SelectDocBuilder) Copy() *SelectDocBuilder
- func (b *SelectDocBuilder) Distinct() *SelectDocBuilder
- func (b *SelectDocBuilder) DistinctOn(columns ...string) *SelectDocBuilder
- func (b *SelectDocBuilder) For(options ...string) *SelectDocBuilder
- func (b *SelectDocBuilder) From(fromStr string, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) FullOuterJoin(joinStr string, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) GroupBy(group string) *SelectDocBuilder
- func (b *SelectDocBuilder) Having(whereSQLOrMap interface{}, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) InnerSQL(sql string, a ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Interpolate() (string, []interface{}, error)
- func (b *SelectDocBuilder) IsInterpolated() bool
- func (b *SelectDocBuilder) Join(joinStr string, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) LeftJoin(joinStr string, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Limit(limit uint64) *SelectDocBuilder
- func (b *SelectDocBuilder) Many(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Offset(offset uint64) *SelectDocBuilder
- func (b *SelectDocBuilder) One(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) OrderBy(whereSQLOrMap interface{}, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Paginate(page, perPage uint64) *SelectDocBuilder
- func (b *SelectDocBuilder) RemoveData() *SelectDocBuilder
- func (b *SelectDocBuilder) RightJoin(joinStr string, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Scalar(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Scope(sql string, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) ScopeMap(mapScope *MapScope, m M) *SelectDocBuilder
- func (b *SelectDocBuilder) SetIsInterpolated(enable bool) *SelectDocBuilder
- func (b *SelectDocBuilder) ToSQL() (string, []interface{}, error)
- func (b *SelectDocBuilder) Union(sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) UnionAll(sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Vector(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *SelectDocBuilder
- func (b *SelectDocBuilder) Whitelist(columns ...string) *SelectDocBuilder
- func (b *SelectDocBuilder) With(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
- type UnsafeString
- type UpdateBuilder
- func (b *UpdateBuilder) CanJSON() bool
- func (b *UpdateBuilder) From(from string) *UpdateBuilder
- func (b *UpdateBuilder) Interpolate() (string, []interface{}, error)
- func (b *UpdateBuilder) IsInterpolated() bool
- func (b *UpdateBuilder) Limit(limit uint64) *UpdateBuilder
- func (b *UpdateBuilder) Offset(offset uint64) *UpdateBuilder
- func (b *UpdateBuilder) OrderBy(ord string) *UpdateBuilder
- func (b *UpdateBuilder) Returning(columns ...string) *UpdateBuilder
- func (b *UpdateBuilder) Scope(sql string, args ...interface{}) *UpdateBuilder
- func (b *UpdateBuilder) ScopeMap(mapScope *MapScope, m M) *UpdateBuilder
- func (b *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder
- func (b *UpdateBuilder) SetBlacklist(rec interface{}, blacklist ...string) *UpdateBuilder
- func (b *UpdateBuilder) SetIsInterpolated(enable bool) *UpdateBuilder
- func (b *UpdateBuilder) SetMap(clauses map[string]interface{}) *UpdateBuilder
- func (b *UpdateBuilder) SetWhitelist(rec interface{}, whitelist ...string) *UpdateBuilder
- func (b *UpdateBuilder) ToSQL() (string, []interface{}, error)
- func (b *UpdateBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *UpdateBuilder
- type UpsertBuilder
- func (b *UpsertBuilder) Blacklist(columns ...string) *UpsertBuilder
- func (b *UpsertBuilder) CanJSON() bool
- func (b *UpsertBuilder) Columns(columns ...string) *UpsertBuilder
- func (b *UpsertBuilder) Interpolate() (string, []interface{}, error)
- func (b *UpsertBuilder) IsInterpolated() bool
- func (b *UpsertBuilder) Record(record interface{}) *UpsertBuilder
- func (b *UpsertBuilder) Returning(columns ...string) *UpsertBuilder
- func (b *UpsertBuilder) SetIsInterpolated(enable bool) *UpsertBuilder
- func (b *UpsertBuilder) ToSQL() (string, []interface{}, error)
- func (b *UpsertBuilder) Values(vals ...interface{}) *UpsertBuilder
- func (b *UpsertBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *UpsertBuilder
- func (b *UpsertBuilder) Whitelist(columns ...string) *UpsertBuilder
Constants ¶
const DEFAULT = UnsafeString("DEFAULT")
DEFAULT SQL value
const EXCLUDED = UnsafeString("EXCLUDED.")
EXCLUDED SQL value in reference to special table for ON CONFLICT
const NOW = UnsafeString("NOW()")
NOW SQL value
Variables ¶
var ( // ErrNotUTF8 ... ErrNotUTF8 = NewError("invalid UTF-8") // ErrInvalidSliceLength ... ErrInvalidSliceLength = NewError("length of slice is 0. length must be >= 1") // ErrInvalidSliceValue ... ErrInvalidSliceValue = NewError("trying to interpolate invalid slice value into query") // ErrInvalidValue ... ErrInvalidValue = NewError("trying to interpolate invalid value into query") // ErrArgumentMismatch ... ErrArgumentMismatch = NewError("mismatch between number of $placeholders and arguments") // ErrTimedout occurs when a query times out. ErrTimedout = NewError("query timed out") // ErrInvalidOperation occurs when an invalid operation occurs like cancelling // an operation without a procPID. ErrInvalidOperation = NewError("invalid operation") // ErrDisconnectedExecer is returned when a dat builder is used directly instead of through sqlx-runner ErrDisconnectedExecer = NewError("dat builders are disconnected, use sqlx-runner package") )
var EnableInterpolation = false
EnableInterpolation enables or disable interpolation
var NameMapping = camelCaseToSnakeCase
NameMapping is the routine to use when mapping column names to struct properties
var Strict = false
Strict tells dat to raise errors
Functions ¶
func Interpolate ¶
Interpolate takes a SQL string with placeholders and a list of arguments to replace them with. Returns a blank string and error if the number of placeholders does not match the number of arguments.
func NewDatSQLErr ¶
NewDatSQLErr returns a ToSQL() compatible error from an error object.
func NewDatSQLError ¶
NewDatSQLError returns a ToSQL() compatible error from a given msg.
func ParseSprocName ¶
ParseSprocName parses the functiname from given string.
Example ParseSprocName("create function foo_bar()") => "foo_bar"
func PartitionKV ¶
PartitionKV parses a reader for sections reder for lines containing a prefix and assingment.
func SQLMapFromFile ¶
SQLMapFromFile loads a file containing special markers and loads the SQL statements into a map.
func SQLMapFromReader ¶
SQLMapFromReader creates a SQL map from an io.Reader.
This string
` --@selectUsers SELECT * FROM users; --@selectAccounts SELECT * FROM accounts; ` returns map[string]string{ "selectUsers": "SELECT * FROM users;", "selectACcounts": "SELECT * FROM accounts;", }
func SQLMapFromString ¶
SQLMapFromString creates a map of strings from s.
func SQLSliceFromFile ¶
SQLSliceFromFile reads a file's text then passes it to SQLSliceFromString.
func SQLSliceFromString ¶
SQLSliceFromString converts a multiline string marked by `^GO$` into a slice of SQL statements.
This string
SELECT * FROM users; GO SELECT * FROM accounts; returns []string{"SELECT *\nFROM users;", "SELECT *\nFROM accounts"}
Types ¶
type Builder ¶
type Builder interface { // ToSQL builds the SQL and arguments from builder. ToSQL() (string, []interface{}, error) // Interpolate builds the interpolation SQL and arguments from builder. // If interpolation flag is disabled then this is just a passthrough to ToSQL. Interpolate() (string, []interface{}, error) // IsInterpolated determines if this builder will interpolate when // Interpolate() is called. IsInterpolated() bool // CanJSON indicates whether this can output JSON CanJSON() bool }
Builder interface is used to tie SQL generators to executors.
type CallBuilder ¶
type CallBuilder struct { Execer // contains filtered or unexported fields }
CallBuilder is a store procedure call builder.
func Call ¶
func Call(sproc string, args ...interface{}) *CallBuilder
Call creates a new CallBuilder for the given sproc and args.
func NewCallBuilder ¶
func NewCallBuilder(sproc string, args ...interface{}) *CallBuilder
NewCallBuilder creates a new CallBuilder for the given sproc name and args.
func (*CallBuilder) CanJSON ¶
func (b *CallBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*CallBuilder) Interpolate ¶
func (b *CallBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*CallBuilder) IsInterpolated ¶
func (b *CallBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*CallBuilder) SetIsInterpolated ¶
func (b *CallBuilder) SetIsInterpolated(enable bool) *CallBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*CallBuilder) ToSQL ¶
func (b *CallBuilder) ToSQL() (string, []interface{}, error)
ToSQL serializes CallBuilder to a SQL string returning valid SQL with placeholders an a slice of query arguments.
type DeleteBuilder ¶
type DeleteBuilder struct { Execer // contains filtered or unexported fields }
DeleteBuilder contains the clauses for a DELETE statement
func DeleteFrom ¶
func DeleteFrom(table string) *DeleteBuilder
DeleteFrom creates a new DeleteBuilder for the given table.
func NewDeleteBuilder ¶
func NewDeleteBuilder(table string) *DeleteBuilder
NewDeleteBuilder creates a new DeleteBuilder for the given table.
func (*DeleteBuilder) CanJSON ¶
func (b *DeleteBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*DeleteBuilder) Interpolate ¶
func (b *DeleteBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*DeleteBuilder) IsInterpolated ¶
func (b *DeleteBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*DeleteBuilder) Returning ¶
func (b *DeleteBuilder) Returning(columns ...string) *DeleteBuilder
Returning sets the columns for the RETURNING clause
func (*DeleteBuilder) Scope ¶
func (b *DeleteBuilder) Scope(sql string, args ...interface{}) *DeleteBuilder
Scope uses a predefined scope in place of WHERE.
func (*DeleteBuilder) ScopeMap ¶
func (b *DeleteBuilder) ScopeMap(mapScope *MapScope, m M) *DeleteBuilder
ScopeMap uses a predefined scope in place of WHERE.
func (*DeleteBuilder) SetIsInterpolated ¶
func (b *DeleteBuilder) SetIsInterpolated(enable bool) *DeleteBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*DeleteBuilder) ToSQL ¶
func (b *DeleteBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the DeleteBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*DeleteBuilder) Where ¶
func (b *DeleteBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *DeleteBuilder
Where appends a WHERE clause to the statement whereSQLOrMap can be a string or map. If it's a string, args wil replaces any places holders
type Eq ¶
type Eq map[string]interface{}
Eq is a map column -> value pairs which must be matched in a query
type Execer ¶
type Execer interface { Cache(id string, ttl time.Duration, invalidate bool) Execer Timeout(time.Duration) Execer Interpolate() (string, []interface{}, error) Exec() (*Result, error) QueryScalar(destinations ...interface{}) error QuerySlice(dest interface{}) error QueryStruct(dest interface{}) error QueryStructs(dest interface{}) error QueryObject(dest interface{}) error QueryJSON() ([]byte, error) }
Execer is any object that executes and queries SQL.
type Expression ¶
type Expression struct { Sql string Args []interface{} }
Expression holds a sub expression.
func Expr ¶
func Expr(sql string, values ...interface{}) *Expression
Expr is a SQL expression with placeholders, and a slice of args to replace them with
func (*Expression) Expression ¶
func (exp *Expression) Expression() (string, []interface{}, error)
Expression implements Expressioner interface (used in Interpolate).
func (*Expression) WriteRelativeArgs ¶
func (exp *Expression) WriteRelativeArgs(buf common.BufferWriter, args *[]interface{}, pos *int64)
WriteRelativeArgs writes the args to buf adjusting the placeholder to start at pos.
type Expressioner ¶
Expressioner is an interface that returns raw SQL with optional placeholders and arguments.
type InsectBuilder ¶
type InsectBuilder struct { Execer // contains filtered or unexported fields }
InsectBuilder inserts or selects an existing row when executed.
// Inserts new row unless there exists a record where // `name='mario' AND email='mario@acme.com'` conn.Insect("people"). Columns("name", "email"). Values("mario", "mario@acme.com"). Returning("id", "name", "email") // Inserts unless there exists a record with ID of 1. // Insect WILL NOT update the row if it exists. conn.Insect("people"). Columns("name", "email"). Values("mario", "mario@acme.com"). Where("id=$1", 1). Returning("id", "name", "email")
func Insect ¶
func Insect(table string) *InsectBuilder
Insect inserts into a table if does not exist.
func NewInsectBuilder ¶
func NewInsectBuilder(table string) *InsectBuilder
NewInsectBuilder creates a new InsectBuilder for the given table.
func (*InsectBuilder) Blacklist ¶
func (b *InsectBuilder) Blacklist(columns ...string) *InsectBuilder
Blacklist defines a blacklist of columns and should only be used in conjunction with Record.
func (*InsectBuilder) CanJSON ¶
func (b *InsectBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*InsectBuilder) Columns ¶
func (b *InsectBuilder) Columns(columns ...string) *InsectBuilder
Columns appends columns to insert in the statement
func (*InsectBuilder) Interpolate ¶
func (b *InsectBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*InsectBuilder) IsInterpolated ¶
func (b *InsectBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*InsectBuilder) Record ¶
func (b *InsectBuilder) Record(record interface{}) *InsectBuilder
Record pulls in values to match Columns from the record
func (*InsectBuilder) Returning ¶
func (b *InsectBuilder) Returning(columns ...string) *InsectBuilder
Returning sets the columns for the RETURNING clause
func (*InsectBuilder) SetIsInterpolated ¶
func (b *InsectBuilder) SetIsInterpolated(enable bool) *InsectBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*InsectBuilder) ToSQL ¶
func (b *InsectBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the InsectBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*InsectBuilder) Values ¶
func (b *InsectBuilder) Values(vals ...interface{}) *InsectBuilder
Values appends a set of values to the statement
func (*InsectBuilder) Where ¶
func (b *InsectBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *InsectBuilder
Where appends a WHERE clause to the statement for the given string and args or map of column/value pairs
func (*InsectBuilder) Whitelist ¶
func (b *InsectBuilder) Whitelist(columns ...string) *InsectBuilder
Whitelist defines a whitelist of columns to be inserted. To specify all columsn of a record use "*".
type InsertBuilder ¶
type InsertBuilder struct { Execer // contains filtered or unexported fields }
InsertBuilder contains the clauses for an INSERT statement
func InsertInto ¶
func InsertInto(table string) *InsertBuilder
InsertInto creates a new InsertBuilder for the given table.
func NewInsertBuilder ¶
func NewInsertBuilder(table string) *InsertBuilder
NewInsertBuilder creates a new InsertBuilder for the given table.
func (*InsertBuilder) Blacklist ¶
func (b *InsertBuilder) Blacklist(columns ...string) *InsertBuilder
Blacklist defines a blacklist of columns and should only be used in conjunction with Record.
func (*InsertBuilder) CanJSON ¶
func (b *InsertBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*InsertBuilder) Columns ¶
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder
Columns appends columns to insert in the statement
func (*InsertBuilder) Interpolate ¶
func (b *InsertBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*InsertBuilder) IsInterpolated ¶
func (b *InsertBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*InsertBuilder) OnConflictColumns ¶
func (b *InsertBuilder) OnConflictColumns(columns ...string) *InsertBuilder
OnConflictColumns is an ON CONFLICT clause with column names as the conflict_target
func (*InsertBuilder) OnConflictConstraint ¶
func (b *InsertBuilder) OnConflictConstraint(constraint string) *InsertBuilder
OnConflictConstraint is an ON CONFLICT clause with a constraint as the conflict_target
func (*InsertBuilder) OnConflictWhere ¶
func (b *InsertBuilder) OnConflictWhere(indexPredicate string, columns ...string) *InsertBuilder
OnConflictWhere is an ON CONFLICT clause with column names and index_predicate as the conflict_target
func (*InsertBuilder) Pair ¶
func (b *InsertBuilder) Pair(column string, value interface{}) *InsertBuilder
Pair adds a key/value pair to the statement
func (*InsertBuilder) Record ¶
func (b *InsertBuilder) Record(record interface{}) *InsertBuilder
Record pulls in values to match Columns from the record
func (*InsertBuilder) Returning ¶
func (b *InsertBuilder) Returning(columns ...string) *InsertBuilder
Returning sets the columns for the RETURNING clause
func (*InsertBuilder) Set ¶
func (b *InsertBuilder) Set(column string, value interface{}) *InsertBuilder
Set may initiate a DO UPDATE conflict_action and sets a column/value pair If never called the conflict_action will default to DO NOTHING
func (*InsertBuilder) SetExcluded ¶
func (b *InsertBuilder) SetExcluded(columns ...string) *InsertBuilder
SetExcluded may initiate a DO UPDATE conflict_action and sets one or more columns to the values proposed for insertion This is a shortcut to setting multiple columns to their proposed insertion values as marked in the special excluded table e.g. rather than Set("a", "EXCLUDED.a").Set("b", "EXCLUDED.b") you may call SetExcluded("a", "b") or SetExcluded("a, b")
func (*InsertBuilder) SetIsInterpolated ¶
func (b *InsertBuilder) SetIsInterpolated(enable bool) *InsertBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*InsertBuilder) SetMap ¶
func (b *InsertBuilder) SetMap(clauses map[string]interface{}) *InsertBuilder
SetMap may initiate a DO UPDATE conflict_action and sets the elements of the map as column/value pairs
func (*InsertBuilder) ToSQL ¶
func (b *InsertBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the InsertBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*InsertBuilder) Values ¶
func (b *InsertBuilder) Values(vals ...interface{}) *InsertBuilder
Values appends a set of values to the statement
func (*InsertBuilder) Where ¶
func (b *InsertBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *InsertBuilder
Where appends a WHERE clause following a conflict_action of DO UPDATE
func (*InsertBuilder) Whitelist ¶
func (b *InsertBuilder) Whitelist(columns ...string) *InsertBuilder
Whitelist defines a whitelist of columns to be inserted. To specify all columns of a record use "*".
type Interpolator ¶
Interpolator is the interface for types which interpolate.
type JSON ¶
type JSON json.RawMessage
JSON is a json.RawMessage, which is a []byte underneath. Value() validates the json format in the source, and returns an error if the json is not valid. Scan does no validation. JSON additionally implements `Unmarshal`, which unmarshals the json within to an interface{}
func JSONFromString ¶
JSONFromString creates a JSON type from JSON encoded string.
func (JSON) Interpolate ¶
Interpolate interpolates the value into a string.
func (JSON) MarshalJSON ¶
MarshalJSON returns the j as the JSON encoding of j.
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON sets *j to a copy of data
type JSQLBuilder ¶
type JSQLBuilder struct { Execer // contains filtered or unexported fields }
JSQLBuilder builds SQL that returns a JSON row.
func JSQL ¶
func JSQL(sql string, args ...interface{}) *JSQLBuilder
JSQL creates a new SelectDocBuilder.
func NewJSQLBuilder ¶
func NewJSQLBuilder(q string, args ...interface{}) *JSQLBuilder
NewJSQLBuilder creates an instance of JSQLBuilder.
func (*JSQLBuilder) CanJSON ¶
func (b *JSQLBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*JSQLBuilder) Interpolate ¶
func (b *JSQLBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*JSQLBuilder) IsInterpolated ¶
func (b *JSQLBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*JSQLBuilder) Many ¶
func (b *JSQLBuilder) Many(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
Many loads a sub query resulting in an array of rows as an alias.
func (*JSQLBuilder) One ¶
func (b *JSQLBuilder) One(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
One loads a query resulting in a single row as an alias.
func (*JSQLBuilder) Scalar ¶
func (b *JSQLBuilder) Scalar(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
Scalar loads a query resulting in a single scalar as an alias and embeds the scalar in the parent object, rather than as a child object
func (*JSQLBuilder) SetIsInterpolated ¶
func (b *JSQLBuilder) SetIsInterpolated(enable bool) *JSQLBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*JSQLBuilder) ToSQL ¶
func (b *JSQLBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the SelectBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*JSQLBuilder) Union ¶
func (b *JSQLBuilder) Union(sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
func (*JSQLBuilder) Vector ¶
func (b *JSQLBuilder) Vector(column string, sqlOrBuilder interface{}, a ...interface{}) *JSQLBuilder
Vector loads a sub query resulting in an array of homogeneous scalars as an alias.
type NullBool ¶
NullBool is a type that can be null or a bool
func NullIfBool ¶
NullIfBool creates a NullBool invalid on equivalency
func (NullBool) MarshalJSON ¶
MarshalJSON correctly serializes a NullBool to JSON
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON correctly deserializes a NullBool from JSON
type NullFloat64 ¶
type NullFloat64 struct {
sql.NullFloat64
}
NullFloat64 is a type that can be null or a float64
func NullFloat64From ¶
func NullFloat64From(v float64) NullFloat64
NullFloat64From creates a valid NullFloat64
func NullIfFloat64 ¶
func NullIfFloat64(v1 float64, v2 float64) NullFloat64
NullIfFloat64 creates a NullFloat64 invalid on equivalency
func (NullFloat64) MarshalJSON ¶
func (n NullFloat64) MarshalJSON() ([]byte, error)
MarshalJSON correctly serializes a NullFloat64 to JSON
func (*NullFloat64) UnmarshalJSON ¶
func (n *NullFloat64) UnmarshalJSON(b []byte) error
UnmarshalJSON correctly deserializes a NullFloat64 from JSON
type NullInt64 ¶
NullInt64 is a type that can be null or an int
func NullIfInt64 ¶
NullIfInt64 creates a NullInt64 invalid on equivalency
func (NullInt64) MarshalJSON ¶
MarshalJSON correctly serializes a NullInt64 to JSON
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON correctly deserializes a NullInt64 from JSON
type NullString ¶
type NullString struct {
sql.NullString
}
NullString is a type that can be null or a string
func NullIfString ¶
func NullIfString(v1 string, v2 string) NullString
NullIfString creates a NullString invalid on equivalency
func NullStringFrom ¶
func NullStringFrom(v string) NullString
NullStringFrom creates a valid NullString
func (NullString) MarshalJSON ¶
func (n NullString) MarshalJSON() ([]byte, error)
MarshalJSON correctly serializes a NullString to JSON
func (*NullString) UnmarshalJSON ¶
func (n *NullString) UnmarshalJSON(b []byte) error
UnmarshalJSON correctly deserializes a NullString from JSON
type NullTime ¶
NullTime is a type that can be null or a time
func NullIfTime ¶
NullIfTime creates a NullTime invalid on equivalency
func (NullTime) MarshalJSON ¶
MarshalJSON correctly serializes a NullTime to JSON
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON correctly deserializes a NullTime from JSON
type RawBuilder ¶
type RawBuilder struct { Execer // contains filtered or unexported fields }
RawBuilder builds SQL from raw SQL.
func NewRawBuilder ¶
func NewRawBuilder(sql string, args ...interface{}) *RawBuilder
NewRawBuilder creates a new RawBuilder for the given SQL string and arguments
func (*RawBuilder) CanJSON ¶
func (b *RawBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*RawBuilder) Interpolate ¶
func (b *RawBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*RawBuilder) IsInterpolated ¶
func (b *RawBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*RawBuilder) SetIsInterpolated ¶
func (b *RawBuilder) SetIsInterpolated(enable bool) *RawBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*RawBuilder) ToSQL ¶
func (b *RawBuilder) ToSQL() (string, []interface{}, error)
ToSQL implements builder interface
type Result ¶
Result serves the same purpose as sql.Result. Defining it for the package avoids tight coupling with database/sql.
type SQLDialect ¶
type SQLDialect interface { // WriteStringLiteral writes a string literal. WriteStringLiteral(buf common.BufferWriter, value string) // WriteIdentifier writes a quoted identifer such as a column or table. WriteIdentifier(buf common.BufferWriter, column string) // WriteFormattedTime writes a time formatted for the database WriteFormattedTime(buf common.BufferWriter, t time.Time) // WriteReflectedType writes a dialect-specfic representation of a given Go type or value WriteReflectedType(buf common.BufferWriter, t interface{}) }
SQLDialect represents a vendor specific SQL dialect.
var Dialect SQLDialect
Dialect is the active SQLDialect.
type SelectBuilder ¶
type SelectBuilder struct { Execer // contains filtered or unexported fields }
SelectBuilder contains the clauses for a SELECT statement
func NewSelectBuilder ¶
func NewSelectBuilder(columns ...string) *SelectBuilder
NewSelectBuilder creates a new SelectBuilder for the given columns
func Select ¶
func Select(columns ...string) *SelectBuilder
Select creates a new SelectBuilder for the given columns.
func (*SelectBuilder) CanJSON ¶
func (b *SelectBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*SelectBuilder) Columns ¶
func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder
Columns adds additional select columns to the builder.
func (*SelectBuilder) Distinct ¶
func (b *SelectBuilder) Distinct() *SelectBuilder
Distinct marks the statement as a DISTINCT SELECT
func (*SelectBuilder) DistinctOn ¶
func (b *SelectBuilder) DistinctOn(columns ...string) *SelectBuilder
DistinctOn sets the columns for DISTINCT ON
func (*SelectBuilder) For ¶
func (b *SelectBuilder) For(options ...string) *SelectBuilder
For adds FOR clause to SELECT.
func (*SelectBuilder) From ¶
func (b *SelectBuilder) From(fromStr string, args ...interface{}) *SelectBuilder
From sets the table to SELECT FROM. JOINs may also be defined here.
func (*SelectBuilder) FullOuterJoin ¶
func (b *SelectBuilder) FullOuterJoin(joinStr string, args ...interface{}) *SelectBuilder
FullOuterJoin appends a full outer join to a FROM
func (*SelectBuilder) GroupBy ¶
func (b *SelectBuilder) GroupBy(group string) *SelectBuilder
GroupBy appends a column to group the statement
func (*SelectBuilder) Having ¶
func (b *SelectBuilder) Having(whereSQLOrMap interface{}, args ...interface{}) *SelectBuilder
Having appends a HAVING clause to the statement
func (*SelectBuilder) Interpolate ¶
func (b *SelectBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*SelectBuilder) IsInterpolated ¶
func (b *SelectBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*SelectBuilder) Join ¶
func (b *SelectBuilder) Join(joinStr string, args ...interface{}) *SelectBuilder
Join appends an inner join to a FROM
func (*SelectBuilder) LeftJoin ¶
func (b *SelectBuilder) LeftJoin(joinStr string, args ...interface{}) *SelectBuilder
LeftJoin appends an left outer join to a FROM
func (*SelectBuilder) Limit ¶
func (b *SelectBuilder) Limit(limit uint64) *SelectBuilder
Limit sets a limit for the statement; overrides any existing LIMIT
func (*SelectBuilder) Offset ¶
func (b *SelectBuilder) Offset(offset uint64) *SelectBuilder
Offset sets an offset for the statement; overrides any existing OFFSET
func (*SelectBuilder) OrderBy ¶
func (b *SelectBuilder) OrderBy(whereSQLOrMap interface{}, args ...interface{}) *SelectBuilder
OrderBy appends a column to ORDER the statement by
func (*SelectBuilder) Paginate ¶
func (b *SelectBuilder) Paginate(page, perPage uint64) *SelectBuilder
Paginate sets LIMIT/OFFSET for the statement based on the given page/perPage Assumes page/perPage are valid. Page and perPage must be >= 1
func (*SelectBuilder) RightJoin ¶
func (b *SelectBuilder) RightJoin(joinStr string, args ...interface{}) *SelectBuilder
RightJoin appends a right outer join to a FROM
func (*SelectBuilder) Scope ¶
func (b *SelectBuilder) Scope(sql string, args ...interface{}) *SelectBuilder
Scope uses a predefined scope in place of WHERE.
func (*SelectBuilder) ScopeMap ¶
func (b *SelectBuilder) ScopeMap(mapScope *MapScope, m M) *SelectBuilder
ScopeMap uses a predefined scope in place of WHERE.
func (*SelectBuilder) SetIsInterpolated ¶
func (b *SelectBuilder) SetIsInterpolated(enable bool) *SelectBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*SelectBuilder) ToSQL ¶
func (b *SelectBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the SelectBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*SelectBuilder) Where ¶
func (b *SelectBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *SelectBuilder
Where appends a WHERE clause to the statement for the given string and args or map of column/value pairs
type SelectDocBuilder ¶
type SelectDocBuilder struct { *SelectBuilder // contains filtered or unexported fields }
SelectDocBuilder builds SQL that returns a JSON row.
func NewSelectDocBuilder ¶
func NewSelectDocBuilder(columns ...string) *SelectDocBuilder
NewSelectDocBuilder creates an instance of SelectDocBuilder.
func SelectDoc ¶
func SelectDoc(columns ...string) *SelectDocBuilder
SelectDoc creates a new SelectDocBuilder for the given columns.
func (*SelectDocBuilder) CanJSON ¶
func (b *SelectDocBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*SelectDocBuilder) Columns ¶
func (b *SelectDocBuilder) Columns(columns ...string) *SelectDocBuilder
Columns adds additional select columns to the builder.
func (*SelectDocBuilder) Copy ¶ added in v1.2.4
func (b *SelectDocBuilder) Copy() *SelectDocBuilder
Copy will produce an independent copy of the SelectDocBuilder such that mutating the copy will not affect the original object
func (*SelectDocBuilder) Distinct ¶
func (b *SelectDocBuilder) Distinct() *SelectDocBuilder
Distinct marks the statement as a DISTINCT SELECT
func (*SelectDocBuilder) DistinctOn ¶
func (b *SelectDocBuilder) DistinctOn(columns ...string) *SelectDocBuilder
DistinctOn sets the columns for DISTINCT ON
func (*SelectDocBuilder) For ¶
func (b *SelectDocBuilder) For(options ...string) *SelectDocBuilder
For adds FOR clause to SELECT.
func (*SelectDocBuilder) From ¶
func (b *SelectDocBuilder) From(fromStr string, args ...interface{}) *SelectDocBuilder
From sets the table to SELECT FROM. JOINs may also be defined here.
func (*SelectDocBuilder) FullOuterJoin ¶
func (b *SelectDocBuilder) FullOuterJoin(joinStr string, args ...interface{}) *SelectDocBuilder
FullOuterJoin appends a full outer join to a FROM
func (*SelectDocBuilder) GroupBy ¶
func (b *SelectDocBuilder) GroupBy(group string) *SelectDocBuilder
GroupBy appends a column to group the statement
func (*SelectDocBuilder) Having ¶
func (b *SelectDocBuilder) Having(whereSQLOrMap interface{}, args ...interface{}) *SelectDocBuilder
Having appends a HAVING clause to the statement
func (*SelectDocBuilder) InnerSQL ¶
func (b *SelectDocBuilder) InnerSQL(sql string, a ...interface{}) *SelectDocBuilder
InnerSQL sets the SQL after the SELECT (columns...) statement
DEPRECATE this
func (*SelectDocBuilder) Interpolate ¶
func (b *SelectDocBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*SelectDocBuilder) IsInterpolated ¶
func (b *SelectDocBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*SelectDocBuilder) Join ¶
func (b *SelectDocBuilder) Join(joinStr string, args ...interface{}) *SelectDocBuilder
Join appends an inner join to a FROM
func (*SelectDocBuilder) LeftJoin ¶
func (b *SelectDocBuilder) LeftJoin(joinStr string, args ...interface{}) *SelectDocBuilder
LeftJoin appends an left outer join to a FROM
func (*SelectDocBuilder) Limit ¶
func (b *SelectDocBuilder) Limit(limit uint64) *SelectDocBuilder
Limit sets a limit for the statement; overrides any existing LIMIT
func (*SelectDocBuilder) Many ¶
func (b *SelectDocBuilder) Many(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
Many loads a sub query resulting in an array of rows as an alias.
func (*SelectDocBuilder) Offset ¶
func (b *SelectDocBuilder) Offset(offset uint64) *SelectDocBuilder
Offset sets an offset for the statement; overrides any existing OFFSET
func (*SelectDocBuilder) One ¶
func (b *SelectDocBuilder) One(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
One loads a query resulting in a single row as an alias.
func (*SelectDocBuilder) OrderBy ¶
func (b *SelectDocBuilder) OrderBy(whereSQLOrMap interface{}, args ...interface{}) *SelectDocBuilder
OrderBy appends a column to ORDER the statement by
func (*SelectDocBuilder) Paginate ¶
func (b *SelectDocBuilder) Paginate(page, perPage uint64) *SelectDocBuilder
Paginate sets LIMIT/OFFSET for the statement based on the given page/perPage Assumes page/perPage are valid. Page and perPage must be >= 1
func (*SelectDocBuilder) RemoveData ¶ added in v1.2.2
func (b *SelectDocBuilder) RemoveData() *SelectDocBuilder
RemoveData will delete all requested columns from this query while leaving other portions of the query intact. This is to allow the rewriting of a pre-built query to only return a small subset of data, e.g. just the ID
func (*SelectDocBuilder) RightJoin ¶
func (b *SelectDocBuilder) RightJoin(joinStr string, args ...interface{}) *SelectDocBuilder
RightJoin appends a right outer join to a FROM
func (*SelectDocBuilder) Scalar ¶
func (b *SelectDocBuilder) Scalar(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
Scalar loads a query resulting in a single scalar as an alias and embeds the scalar in the parent object, rather than as a child object
func (*SelectDocBuilder) Scope ¶
func (b *SelectDocBuilder) Scope(sql string, args ...interface{}) *SelectDocBuilder
Scope uses a predefined scope in place of WHERE.
func (*SelectDocBuilder) ScopeMap ¶
func (b *SelectDocBuilder) ScopeMap(mapScope *MapScope, m M) *SelectDocBuilder
ScopeMap uses a predefined scope in place of WHERE.
func (*SelectDocBuilder) SetIsInterpolated ¶
func (b *SelectDocBuilder) SetIsInterpolated(enable bool) *SelectDocBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*SelectDocBuilder) ToSQL ¶
func (b *SelectDocBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the SelectBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*SelectDocBuilder) Union ¶
func (b *SelectDocBuilder) Union(sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
Union will add a SQL expression to the query with a UNION directive
func (*SelectDocBuilder) UnionAll ¶
func (b *SelectDocBuilder) UnionAll(sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
UnionAll will add a SQL expression to the query with a UNION ALL directive
func (*SelectDocBuilder) Vector ¶
func (b *SelectDocBuilder) Vector(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
Vector loads a sub query resulting in an array of homogeneous scalars as an alias.
func (*SelectDocBuilder) Where ¶
func (b *SelectDocBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *SelectDocBuilder
Where appends a WHERE clause to the statement for the given string and args or map of column/value pairs
func (*SelectDocBuilder) Whitelist ¶
func (b *SelectDocBuilder) Whitelist(columns ...string) *SelectDocBuilder
Whitelist will drop any named columns from the query that are not included in the whitelist. An empty parameter list is a no-op. Columns with a trailing * character are treated as a prefix match instead of whole-word match. This does _not_ affect union queries.
func (*SelectDocBuilder) With ¶
func (b *SelectDocBuilder) With(column string, sqlOrBuilder interface{}, a ...interface{}) *SelectDocBuilder
With loads a sub query that will be inserted as a "with" table
type UnsafeString ¶
type UnsafeString string
UnsafeString is interpolated as an unescaped and unquoted value and should only be used to create constants.
type UpdateBuilder ¶
type UpdateBuilder struct { Execer // contains filtered or unexported fields }
UpdateBuilder contains the clauses for an UPDATE statement
func NewUpdateBuilder ¶
func NewUpdateBuilder(table string) *UpdateBuilder
NewUpdateBuilder creates a new UpdateBuilder for the given table
func Update ¶
func Update(table string) *UpdateBuilder
Update creates a new UpdateBuilder for the given table.
func (*UpdateBuilder) CanJSON ¶
func (b *UpdateBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*UpdateBuilder) From ¶
func (b *UpdateBuilder) From(from string) *UpdateBuilder
From sets the fromList to UPDATE FROM. JOINs may also be defined here. Allows columns from other tables to appear in the WHERE condition and the update expressions.
func (*UpdateBuilder) Interpolate ¶
func (b *UpdateBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*UpdateBuilder) IsInterpolated ¶
func (b *UpdateBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*UpdateBuilder) Limit ¶
func (b *UpdateBuilder) Limit(limit uint64) *UpdateBuilder
Limit sets a limit for the statement; overrides any existing LIMIT
func (*UpdateBuilder) Offset ¶
func (b *UpdateBuilder) Offset(offset uint64) *UpdateBuilder
Offset sets an offset for the statement; overrides any existing OFFSET
func (*UpdateBuilder) OrderBy ¶
func (b *UpdateBuilder) OrderBy(ord string) *UpdateBuilder
OrderBy appends a column to ORDER the statement by
func (*UpdateBuilder) Returning ¶
func (b *UpdateBuilder) Returning(columns ...string) *UpdateBuilder
Returning sets the columns for the RETURNING clause
func (*UpdateBuilder) Scope ¶
func (b *UpdateBuilder) Scope(sql string, args ...interface{}) *UpdateBuilder
Scope uses a predefined scope in place of WHERE.
func (*UpdateBuilder) ScopeMap ¶
func (b *UpdateBuilder) ScopeMap(mapScope *MapScope, m M) *UpdateBuilder
ScopeMap uses a predefined scope in place of WHERE.
func (*UpdateBuilder) Set ¶
func (b *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder
Set appends a column/value pair for the statement
func (*UpdateBuilder) SetBlacklist ¶
func (b *UpdateBuilder) SetBlacklist(rec interface{}, blacklist ...string) *UpdateBuilder
SetBlacklist creates SET clause(s) using a record and blacklist of columns
func (*UpdateBuilder) SetIsInterpolated ¶
func (b *UpdateBuilder) SetIsInterpolated(enable bool) *UpdateBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*UpdateBuilder) SetMap ¶
func (b *UpdateBuilder) SetMap(clauses map[string]interface{}) *UpdateBuilder
SetMap appends the elements of the map as column/value pairs for the statement
func (*UpdateBuilder) SetWhitelist ¶
func (b *UpdateBuilder) SetWhitelist(rec interface{}, whitelist ...string) *UpdateBuilder
SetWhitelist creates SET clause(s) using a record and whitelist of columns. To specify all columns, use "*".
func (*UpdateBuilder) ToSQL ¶
func (b *UpdateBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the UpdateBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*UpdateBuilder) Where ¶
func (b *UpdateBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *UpdateBuilder
Where appends a WHERE clause to the statement
type UpsertBuilder ¶
type UpsertBuilder struct { Execer // contains filtered or unexported fields }
UpsertBuilder contains the clauses for an INSERT statement
func NewUpsertBuilder ¶
func NewUpsertBuilder(table string) *UpsertBuilder
NewUpsertBuilder creates a new UpsertBuilder for the given table.
func Upsert ¶
func Upsert(table string) *UpsertBuilder
Upsert insert (if it does not exist) or updates a row.
func (*UpsertBuilder) Blacklist ¶
func (b *UpsertBuilder) Blacklist(columns ...string) *UpsertBuilder
Blacklist defines a blacklist of columns and should only be used in conjunction with Record.
func (*UpsertBuilder) CanJSON ¶
func (b *UpsertBuilder) CanJSON() bool
CanJSON determines if a builder can output JSON.
func (*UpsertBuilder) Columns ¶
func (b *UpsertBuilder) Columns(columns ...string) *UpsertBuilder
Columns appends columns to insert in the statement
func (*UpsertBuilder) Interpolate ¶
func (b *UpsertBuilder) Interpolate() (string, []interface{}, error)
Interpolate interpolates this builders sql.
func (*UpsertBuilder) IsInterpolated ¶
func (b *UpsertBuilder) IsInterpolated() bool
IsInterpolated determines if this builder will interpolate when Interpolate() is called.
func (*UpsertBuilder) Record ¶
func (b *UpsertBuilder) Record(record interface{}) *UpsertBuilder
Record pulls in values to match Columns from the record
func (*UpsertBuilder) Returning ¶
func (b *UpsertBuilder) Returning(columns ...string) *UpsertBuilder
Returning sets the columns for the RETURNING clause
func (*UpsertBuilder) SetIsInterpolated ¶
func (b *UpsertBuilder) SetIsInterpolated(enable bool) *UpsertBuilder
SetIsInterpolated sets whether this builder should interpolate.
func (*UpsertBuilder) ToSQL ¶
func (b *UpsertBuilder) ToSQL() (string, []interface{}, error)
ToSQL serialized the UpsertBuilder to a SQL string It returns the string with placeholders and a slice of query arguments
func (*UpsertBuilder) Values ¶
func (b *UpsertBuilder) Values(vals ...interface{}) *UpsertBuilder
Values appends a set of values to the statement
func (*UpsertBuilder) Where ¶
func (b *UpsertBuilder) Where(whereSQLOrMap interface{}, args ...interface{}) *UpsertBuilder
Where appends a WHERE clause to the statement for the given string and args or map of column/value pairs
func (*UpsertBuilder) Whitelist ¶
func (b *UpsertBuilder) Whitelist(columns ...string) *UpsertBuilder
Whitelist defines a whitelist of columns to be inserted. To specify all columsn of a record use "*".