Documentation ¶
Index ¶
- Constants
- func BoolSliceArgs(src ...bool) []interface{}
- func CompileQuery(sql string, opts ...CompileQueryOption) (query string, err error)
- func CompliantName(in string) string
- func ExpandAsColumns(cols ...string) []string
- func Int16SliceArgs(src ...int16) []interface{}
- func Int32SliceArgs(src ...int32) []interface{}
- func Int8SliceArgs(src ...int8) []interface{}
- func IntSliceArgs(src ...int) []interface{}
- func JoinColumns(cols ...string) string
- func JoinColumnsWithAs(cols ...string) string
- func JoinTableColumns(table string, cols ...string) string
- func JoinTableColumnsValues(cmp string, table string, cols ...string) string
- func JoinTableColumnsWithAs(table string, cols ...string) string
- func JoinTableValues(cols ...string) string
- func NamedUnbindVars(stmt sqlparser.Statement, withAlias bool, arg interface{}) error
- func Pagination(limit, offset int) string
- func Placeholders(n int) string
- func StringSliceArgs(src ...string) []interface{}
- func TableColumns(table string, cols ...string) []string
- func TableColumnsValues(cmp string, table string, cols ...string) []string
- func TableValues(cols ...string) []string
- func TimeSliceArgs(src ...time.Time) []interface{}
- func TrimExpr(expr sqlparser.Expr, arg interface{}) sqlparser.Expr
- func TrimInsert(insert *sqlparser.Insert, arg interface{}) error
- func TrimUpdate(update *sqlparser.Update, arg interface{}) error
- func TrimWhere(where *sqlparser.Where, arg interface{})
- func Uint16SliceArgs(src ...uint16) []interface{}
- func Uint32SliceArgs(src ...uint32) []interface{}
- func Uint8SliceArgs(src ...uint8) []interface{}
- func UintSliceArgs(src ...uint) []interface{}
- type CompileQueryOption
- type CompileQueryOptionFunc
- type EmptyCompileQueryOption
- type NullDuration
- type NullJson
Constants ¶
const (
TagDb = "db"
)
Variables ¶
This section is empty.
Functions ¶
func BoolSliceArgs ¶ added in v0.0.70
func BoolSliceArgs(src ...bool) []interface{}
func CompileQuery ¶ added in v0.0.69
func CompileQuery(sql string, opts ...CompileQueryOption) (query string, err error)
CompileQuery compiles a unbound query (using the '?' bind var) into an NamedQuery. WithCompileQueryOptionAliasWithSelect, default true SELECT t.a, b FROM t
TO
select t.a as t_a, b as b
INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?) TO insert into foo(a, b, c, d) values (:a, :b, :c, :d)
func CompliantName ¶ added in v0.0.69
CompliantName returns a compliant id name that can be used for a bind or as var. replace special runes with '_' a.b -> a_b
func ExpandAsColumns ¶ added in v0.0.71
ExpandAsColumns expand columns with alias AS query := ExpandAsColumns("table.foo", "bar") // []string{"table.foo AS table_foo", "bar AS bar"}
func Int16SliceArgs ¶ added in v0.0.70
func Int16SliceArgs(src ...int16) []interface{}
func Int32SliceArgs ¶ added in v0.0.70
func Int32SliceArgs(src ...int32) []interface{}
func Int8SliceArgs ¶ added in v0.0.70
func Int8SliceArgs(src ...int8) []interface{}
func IntSliceArgs ¶ added in v0.0.70
func IntSliceArgs(src ...int) []interface{}
func JoinColumns ¶ added in v0.0.71
JoinColumns concatenates the elements of cols to column1, column2, ... query := JoinColumns("foo", "bar") // "foo,bar"
func JoinColumnsWithAs ¶ added in v0.0.71
JoinColumnsWithAs concatenates the elements of cols to column1, column2, ... query := JoinColumnsWithAs("foo", "bar") // "foo AS foo,bar AS bar"
func JoinTableColumns ¶ added in v0.0.71
JoinTableColumns concatenates the elements of cols to column1, column2, ... query := JoinTableColumns("table", "foo", "bar") // "table.foo, table.bar"
func JoinTableColumnsValues ¶ added in v0.0.71
JoinTableColumnsValues concatenates the elements of values to table.value1=:value1, table.value2=:value2 ... query := JoinTableColumnsValues("table", "foo", "bar") // "table.foo=?, table.bar=?"
func JoinTableColumnsWithAs ¶ added in v0.0.71
JoinTableColumnsWithAs concatenates the elements of cols to column1, column2, ... query := JoinTableColumnsWithAs("table", "foo", "bar") // "table.foo AS table.foo, table.bar AS table.bar"
func JoinTableValues ¶ added in v0.0.71
JoinTableValues concatenates the elements of values to :value1, :value2, ... query := JoinTableValues("foo", "bar") // "?,?" query := JoinTableValues() // ""
func NamedUnbindVars ¶ added in v0.0.69
NamedUnbindVars rewrites unbind vars to named vars referenced in the statement. Ideally, this should be done only once.
func Pagination ¶ added in v0.0.71
Pagination returns the "LIMIT %d, OFFSET %d" query := Pagination(0, 0) // "LIMIT 0, OFFSET 0"
func Placeholders ¶ added in v0.0.68
Placeholders behaves like strings.Join([]string{"?",...,"?"}, ",")
func StringSliceArgs ¶ added in v0.0.70
func StringSliceArgs(src ...string) []interface{}
func TableColumns ¶ added in v0.0.71
TableColumns returns the []string{table.value1, table.value2 ...} query := Columns("table", "foo", "bar") // []string{"table.foo", "table.bar"}
func TableColumnsValues ¶ added in v0.0.71
ColumnsValues returns the []string{table.value1=:value1, table.value2=:value2 ...} query := ColumnsValues("table", "foo", "bar") // []string{"table.foo=?", "table.bar=?"}
func TableValues ¶ added in v0.0.71
TableValues returns the []string{:value1, :value2 ...} query := TableValues("foo", "bar") // []string{"?", "?"}
func TimeSliceArgs ¶ added in v0.0.70
func TrimInsert ¶ added in v0.0.69
func TrimUpdate ¶ added in v0.0.69
func Uint16SliceArgs ¶ added in v0.0.70
func Uint16SliceArgs(src ...uint16) []interface{}
func Uint32SliceArgs ¶ added in v0.0.70
func Uint32SliceArgs(src ...uint32) []interface{}
func Uint8SliceArgs ¶ added in v0.0.70
func Uint8SliceArgs(src ...uint8) []interface{}
func UintSliceArgs ¶ added in v0.0.70
func UintSliceArgs(src ...uint) []interface{}
Types ¶
type CompileQueryOption ¶ added in v0.0.69
type CompileQueryOption interface {
// contains filtered or unexported methods
}
A CompileQueryOption sets options.
func WithCompileQueryOptionAliasWithSelect ¶ added in v0.0.69
func WithCompileQueryOptionAliasWithSelect(aliasWithSelect bool) CompileQueryOption
WithCompileQueryOptionAliasWithSelect Generate Alias `SELECT t.a, b` TO `select t.a as t_a, b as b`,
func WithCompileQueryOptionArgument ¶ added in v0.0.69
func WithCompileQueryOptionArgument(arg interface{}) CompileQueryOption
WithCompileQueryOptionArgument keep column if argument by column name is not zero take effect in WHERE|INSERT|UPDATE, ignore if multi rows nil: keep all []string: keep if exist map[string]{{value}} : keep if exist and none zero struct{} tag is `db:"{{col_name}}"`: keep if exist and none zero
`SELECT t.a, b FROM t WHERE first_name= :hehe AND middle_name=? OR last_name=?` TO `select t.a as t_a, b as b from t where first_name = :first_name or last_name = :last_name`,
type CompileQueryOptionFunc ¶ added in v0.0.69
type CompileQueryOptionFunc func(*compileQuery)
CompileQueryOptionFunc wraps a function that modifies compileQuery into an implementation of the CompileQueryOption interface.
type EmptyCompileQueryOption ¶ added in v0.0.69
type EmptyCompileQueryOption struct{}
EmptyCompileQueryOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type NullDuration ¶
NullDuration represents an interface that may be null. NullDuration implements the Scanner interface so it can be used as a scan destination, similar to sql.NullString.
func (*NullDuration) Scan ¶
func (nj *NullDuration) Scan(src interface{}) error
Scan implements the sql.Scanner interface.
type NullJson ¶
type NullJson struct { Data interface{} // must be set with a pointer to zero value of expect type Valid bool // Valid is true if Data is not NULL }
NullJson represents an interface that may be null. NullJson implements the Scanner interface so it can be used as a scan destination, similar to sql.NullString. Deprecate, use go-nulljson instead. For more information, see: https://godoc.org/github.com/searKing/golang/tools/cmd/go-nulljson