sql

package
v0.0.82 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

func CompliantName(in string) string

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

func ExpandAsColumns(cols ...string) []string

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

func JoinColumns(cols ...string) string

JoinColumns concatenates the elements of cols to column1, column2, ... query := JoinColumns("foo", "bar") // "foo,bar"

func JoinColumnsWithAs added in v0.0.71

func JoinColumnsWithAs(cols ...string) string

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

func JoinTableColumns(table string, cols ...string) string

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

func JoinTableColumnsValues(cmp string, table string, cols ...string) string

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

func JoinTableColumnsWithAs(table string, cols ...string) string

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

func JoinTableValues(cols ...string) string

JoinTableValues concatenates the elements of values to :value1, :value2, ... query := JoinTableValues("foo", "bar") // "?,?" query := JoinTableValues() // ""

func NamedUnbindVars added in v0.0.69

func NamedUnbindVars(stmt sqlparser.Statement, withAlias bool, arg interface{}) error

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

func Pagination(limit, offset int) string

Pagination returns the "LIMIT %d, OFFSET %d" query := Pagination(0, 0) // "LIMIT 0, OFFSET 0"

func Placeholders added in v0.0.68

func Placeholders(n int) string

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

func TableColumns(table string, cols ...string) []string

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

func TableColumnsValues(cmp string, table string, cols ...string) []string

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

func TableValues(cols ...string) []string

TableValues returns the []string{:value1, :value2 ...} query := TableValues("foo", "bar") // []string{"?", "?"}

func TimeSliceArgs added in v0.0.70

func TimeSliceArgs(src ...time.Time) []interface{}

func TrimExpr added in v0.0.69

func TrimExpr(expr sqlparser.Expr, arg interface{}) sqlparser.Expr

func TrimInsert added in v0.0.69

func TrimInsert(insert *sqlparser.Insert, arg interface{}) error

func TrimUpdate added in v0.0.69

func TrimUpdate(update *sqlparser.Update, arg interface{}) error

func TrimWhere added in v0.0.69

func TrimWhere(where *sqlparser.Where, arg interface{})

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

type NullDuration struct {
	Data time.Duration

	Valid bool // Valid is true if Data is not NULL
}

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.

func (NullDuration) Value

func (nj NullDuration) Value() (driver.Value, error)

Value implements the driver.Valuer 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

func (*NullJson) Scan

func (nj *NullJson) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (NullJson) Value

func (nj NullJson) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL