Documentation
¶
Overview ¶
Package hey is a helper that quickly responds to the results of insert, delete, update, select sql statements. You can also use hey to quickly build sql statements.
Index ¶
- Constants
- Variables
- func ArgString(i interface{}) string
- func BasicTypeValue(value interface{}) interface{}
- func ConcatString(sss ...string) string
- func EvenSlice2Map[K comparable](elems ...K) map[K]K
- func LastNotEmptyString(sss []string) string
- func MergeMap[K comparable, V interface{}](elems ...map[K]V) map[K]V
- func MergeSlice[V interface{}](elems ...[]V) []V
- func MustAffectedRows(affectedRows int64, err error) error
- func PrepareString(prepare string, args []interface{}) string
- func RemoveDuplicate(dynamic ...interface{}) (result []interface{})
- func RemoveDuplicates[T comparable](dynamic ...T) (result []T)
- func RemoveSliceMemberByIndex[T interface{}](indexList []int, elementList []T) []T
- func ScanAll(rows *sql.Rows, fc func(rows *sql.Rows) error) (err error)
- func ScanOne(rows *sql.Rows, dest ...interface{}) error
- func ScanSliceStruct(rows *sql.Rows, result interface{}, tag string) error
- func ScanViewMap(rows *sql.Rows) ([]map[string]interface{}, error)
- func Slice2MapNewKey[K comparable](elems []K, createKey func(v K) K) map[K]K
- func Slice2MapNewVal[K comparable, V interface{}](elems []K, createValue func(v K) V) map[K]V
- func SliceIter[V interface{}](iter func(v V) V, elems []V) []V
- func SliceMatchMap[K comparable, X interface{}, Y interface{}](kx map[K]X, handle func(x X, y Y), key func(y Y) K, elems []Y)
- func SqlAlias(name string, alias string) string
- func SqlPrefix(prefix string, name string) string
- func StructInsert(object interface{}, tag string, except []string, allow []string) (fields []string, values [][]interface{})
- func StructModify(object interface{}, tag string, except ...string) (fields []string, values []interface{})
- func StructObtain(object interface{}, tag string, except ...string) (fields []string, values []interface{})
- func StructUpdate(origin interface{}, latest interface{}, tag string, except ...string) (fields []string, values []interface{})
- type Add
- func (s *Add) Add() (int64, error)
- func (s *Add) Comment(comment string) *Add
- func (s *Add) Context(ctx context.Context) *Add
- func (s *Add) Create(create interface{}) *Add
- func (s *Add) DefaultFieldValue(field string, value interface{}) *Add
- func (s *Add) Except(except ...string) *Add
- func (s *Add) FieldValue(field string, value interface{}) *Add
- func (s *Add) Fields(fields []string) *Add
- func (s *Add) FieldsValues(fields []string, values [][]interface{}) *Add
- func (s *Add) OnConflict(prepare string, args []interface{}) *Add
- func (s *Add) Returning(fc func(row *sql.Row) error, returning ...string) error
- func (s *Add) SQL() (prepare string, args []interface{})
- func (s *Add) Table(table string) *Add
- func (s *Add) UseResult(fc func(result sql.Result) error) *Add
- func (s *Add) Values(values [][]interface{}) *Add
- func (s *Add) ValuesSubQuery(prepare string, args ...interface{}) *Add
- func (s *Add) ValuesSubQueryGet(get *Get) *Add
- func (s *Add) Way() *Way
- type Caller
- type Commander
- type Config
- type Del
- func (s *Del) Comment(comment string) *Del
- func (s *Del) Context(ctx context.Context) *Del
- func (s *Del) Del() (int64, error)
- func (s *Del) F(filter ...Filter) Filter
- func (s *Del) SQL() (prepare string, args []interface{})
- func (s *Del) Table(table string) *Del
- func (s *Del) Way() *Way
- func (s *Del) Where(where Filter) *Del
- type Filter
- type Get
- func (s *Get) Alias(alias string) *Get
- func (s *Get) AppendColumn(column ...string) *Get
- func (s *Get) Asc(column string) *Get
- func (s *Get) Column(column ...string) *Get
- func (s *Get) Comment(comment string) *Get
- func (s *Get) Context(ctx context.Context) *Get
- func (s *Get) Count(column ...string) (count int64, err error)
- func (s *Get) CountGet(result interface{}, countColumn ...string) (int64, error)
- func (s *Get) CountQuery(query func(rows *sql.Rows) (err error), countColumn ...string) (int64, error)
- func (s *Get) Desc(column string) *Get
- func (s *Get) Exists() (exists bool, err error)
- func (s *Get) F(filter ...Filter) Filter
- func (s *Get) FullJoin(fs ...func(j *GetJoin)) *Get
- func (s *Get) Get(result interface{}) error
- func (s *Get) Group(group ...string) *Get
- func (s *Get) Having(having Filter) *Get
- func (s *Get) InnerJoin(fs ...func(j *GetJoin)) *Get
- func (s *Get) Joins(joins ...*GetJoin) *Get
- func (s *Get) LeftJoin(fs ...func(j *GetJoin)) *Get
- func (s *Get) Limit(limit int64) *Get
- func (s *Get) Limiter(limiter Limiter) *Get
- func (s *Get) Offset(offset int64) *Get
- func (s *Get) Order(order string, orderMap ...map[string]string) *Get
- func (s *Get) Query(query func(rows *sql.Rows) (err error)) error
- func (s *Get) RightJoin(fs ...func(j *GetJoin)) *Get
- func (s *Get) SQL() (prepare string, args []interface{})
- func (s *Get) SQLCount(columns ...string) (prepare string, args []interface{})
- func (s *Get) ScanAll(fc func(rows *sql.Rows) error) error
- func (s *Get) ScanOne(dest ...interface{}) error
- func (s *Get) SubQuery(prepare string, args ...interface{}) *Get
- func (s *Get) SubQueryGet(get *Get, alias ...string) *Get
- func (s *Get) Table(table string, alias ...string) *Get
- func (s *Get) Union(prepare string, args ...interface{}) *Get
- func (s *Get) UnionAll(prepare string, args ...interface{}) *Get
- func (s *Get) UnionAllGet(get ...*Get) *Get
- func (s *Get) UnionGet(get ...*Get) *Get
- func (s *Get) ViewMap() (result []map[string]interface{}, err error)
- func (s *Get) Way() *Way
- func (s *Get) Where(where Filter) *Get
- func (s *Get) With(alias string, prepare string, args ...interface{}) *Get
- func (s *Get) WithGet(alias string, get *Get) *Get
- type GetJoin
- func (s *GetJoin) Alias(alias string) *GetJoin
- func (s *GetJoin) Column(column ...string) *GetJoin
- func (s *GetJoin) GetColumn() []string
- func (s *GetJoin) On(on string) *GetJoin
- func (s *GetJoin) OnEqual(fields ...string) *GetJoin
- func (s *GetJoin) SQL() (prepare string, args []interface{})
- func (s *GetJoin) SubQuery(prepare string, args ...interface{}) *GetJoin
- func (s *GetJoin) SubQueryGet(get *Get, alias ...string) *GetJoin
- func (s *GetJoin) Table(table string) *GetJoin
- func (s *GetJoin) Using(fields ...string) *GetJoin
- type Ident
- func (s *Ident) AVG(field string) string
- func (s *Ident) Avg(field string, alias ...string) string
- func (s *Ident) COUNT(field string, alias ...string) string
- func (s *Ident) Field(field ...string) []string
- func (s *Ident) MAX(field string) string
- func (s *Ident) MIN(field string) string
- func (s *Ident) Max(field string, alias ...string) string
- func (s *Ident) Min(field string, alias ...string) string
- func (s *Ident) SUM(field string) string
- func (s *Ident) Sum(field string, alias ...string) string
- func (s *Ident) V(sss ...string) string
- type Limiter
- type LogArgs
- type LogSQL
- type LogTrans
- type Mod
- func (s *Mod) Comment(comment string) *Mod
- func (s *Mod) Context(ctx context.Context) *Mod
- func (s *Mod) Decr(field string, value interface{}) *Mod
- func (s *Mod) DefaultDecr(field string, value interface{}) *Mod
- func (s *Mod) DefaultExpr(field string, expr string, args ...interface{}) *Mod
- func (s *Mod) DefaultIncr(field string, value interface{}) *Mod
- func (s *Mod) DefaultSet(field string, value interface{}) *Mod
- func (s *Mod) Except(except ...string) *Mod
- func (s *Mod) Expr(field string, expr string, args ...interface{}) *Mod
- func (s *Mod) F(filter ...Filter) Filter
- func (s *Mod) FieldsValues(fields []string, values []interface{}) *Mod
- func (s *Mod) Incr(field string, value interface{}) *Mod
- func (s *Mod) Mod() (int64, error)
- func (s *Mod) Modify(modify interface{}) *Mod
- func (s *Mod) SQL() (prepare string, args []interface{})
- func (s *Mod) Set(field string, value interface{}) *Mod
- func (s *Mod) SetSQL() (prepare string, args []interface{})
- func (s *Mod) Table(table string) *Mod
- func (s *Mod) Update(originObject interface{}, latestObject interface{}) *Mod
- func (s *Mod) Way() *Way
- func (s *Mod) Where(where Filter) *Mod
- type Opts
- func WithConfig(config *Config) Opts
- func WithLogger(log func(log *LogSQL)) Opts
- func WithPrepare(fix func(prepare string) string) Opts
- func WithReader(reader Reader) Opts
- func WithScan(scan func(rows *sql.Rows, result interface{}, tag string) error) Opts
- func WithTag(tag string) Opts
- func WithTxLogger(txLog func(log *LogTrans)) Opts
- func WithTxOpts(txOpts *sql.TxOptions) Opts
- type PrepareArgs
- type Reader
- type Stmt
- func (s *Stmt) Close() (err error)
- func (s *Stmt) Exec(args ...interface{}) (int64, error)
- func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (int64, error)
- func (s *Stmt) Execute(args ...interface{}) (sql.Result, error)
- func (s *Stmt) ExecuteContext(ctx context.Context, args ...interface{}) (sql.Result, error)
- func (s *Stmt) Query(query func(rows *sql.Rows) error, args ...interface{}) error
- func (s *Stmt) QueryContext(ctx context.Context, query func(rows *sql.Rows) error, args ...interface{}) error
- func (s *Stmt) QueryRow(query func(rows *sql.Row) error, args ...interface{}) (err error)
- func (s *Stmt) QueryRowContext(ctx context.Context, query func(rows *sql.Row) error, args ...interface{}) error
- func (s *Stmt) TakeAll(result interface{}, args ...interface{}) error
- func (s *Stmt) TakeAllContext(ctx context.Context, result interface{}, args ...interface{}) error
- type SubQuery
- type TxArgs
- type Way
- func (s *Way) Add(table string) *Add
- func (s *Way) AliasA() *Ident
- func (s *Way) AliasB() *Ident
- func (s *Way) AliasC() *Ident
- func (s *Way) AliasD() *Ident
- func (s *Way) AliasE() *Ident
- func (s *Way) AliasF() *Ident
- func (s *Way) AliasG() *Ident
- func (s *Way) DB() *sql.DB
- func (s *Way) Del(table string) *Del
- func (s *Way) Exec(prepare string, args ...interface{}) (int64, error)
- func (s *Way) ExecContext(ctx context.Context, prepare string, args ...interface{}) (int64, error)
- func (s *Way) Execute(prepare string, args ...interface{}) (sql.Result, error)
- func (s *Way) ExecuteContext(ctx context.Context, prepare string, args ...interface{}) (sql.Result, error)
- func (s *Way) F(filter ...Filter) Filter
- func (s *Way) Get(table ...string) *Get
- func (s *Way) Getter(query func(rows *sql.Rows) error, prepare string, caller ...Caller) error
- func (s *Way) GetterContext(ctx context.Context, query func(rows *sql.Rows) error, prepare string, ...) (err error)
- func (s *Way) Ident(prefix ...string) *Ident
- func (s *Way) IsRead() bool
- func (s *Way) Mod(table string) *Mod
- func (s *Way) Now() time.Time
- func (s *Way) Prepare(prepare string, caller ...Caller) (*Stmt, error)
- func (s *Way) PrepareContext(ctx context.Context, prepare string, caller ...Caller) (*Stmt, error)
- func (s *Way) Query(query func(rows *sql.Rows) error, prepare string, args ...interface{}) error
- func (s *Way) QueryContext(ctx context.Context, query func(rows *sql.Rows) error, prepare string, ...) error
- func (s *Way) QueryRow(query func(row *sql.Row) error, prepare string, args ...interface{}) error
- func (s *Way) QueryRowContext(ctx context.Context, query func(row *sql.Row) error, prepare string, ...) error
- func (s *Way) Read() *Way
- func (s *Way) ScanAll(rows *sql.Rows, fc func(rows *sql.Rows) error) error
- func (s *Way) ScanOne(rows *sql.Rows, dest ...interface{}) error
- func (s *Way) Setter(prepare string, caller ...Caller) (int64, error)
- func (s *Way) SetterContext(ctx context.Context, prepare string, caller ...Caller) (int64, error)
- func (s *Way) Tag() string
- func (s *Way) TakeAll(result interface{}, prepare string, args ...interface{}) error
- func (s *Way) TakeAllContext(ctx context.Context, result interface{}, prepare string, args ...interface{}) error
- func (s *Way) TxMsg(msg string) *Way
- func (s *Way) TxNil() bool
- func (s *Way) TxTry(fc func(tx *Way) error, args ...*TxArgs) error
- func (s *Way) TxTryCtx(ctx context.Context, fc func(tx *Way) error, args ...*TxArgs) (err error)
- type WindowFunc
- func (s *WindowFunc) Alias(alias string) *WindowFunc
- func (s *WindowFunc) Asc(column string) *WindowFunc
- func (s *WindowFunc) Avg(column string) *WindowFunc
- func (s *WindowFunc) Count(column string) *WindowFunc
- func (s *WindowFunc) DenseRank() *WindowFunc
- func (s *WindowFunc) Desc(column string) *WindowFunc
- func (s *WindowFunc) FirstValue(column string) *WindowFunc
- func (s *WindowFunc) Lag(column string, offset int64, defaultValue any) *WindowFunc
- func (s *WindowFunc) LastValue(column string) *WindowFunc
- func (s *WindowFunc) Lead(column string, offset int64, defaultValue any) *WindowFunc
- func (s *WindowFunc) Max(column string) *WindowFunc
- func (s *WindowFunc) Min(column string) *WindowFunc
- func (s *WindowFunc) NthValue(column string, LineNumber int64) *WindowFunc
- func (s *WindowFunc) Ntile(buckets int64) *WindowFunc
- func (s *WindowFunc) Partition(column ...string) *WindowFunc
- func (s *WindowFunc) Rank() *WindowFunc
- func (s *WindowFunc) Result() string
- func (s *WindowFunc) RowNumber() *WindowFunc
- func (s *WindowFunc) Sum(column string) *WindowFunc
- func (s *WindowFunc) WindowFrame(windowFrame string) *WindowFunc
- func (s *WindowFunc) WithFunc(withFunc string) *WindowFunc
- type WithQuery
Constants ¶
const ( State0 = 0 State1 = 1 StateNo = "NO" StateYes = "YES" StateOn = "ON" StateOff = "OFF" )
const ( // DefaultTag Mapping of default database column name and struct tag. DefaultTag = "db" // EmptyString Empty string value. EmptyString = "" )
const ( SqlDollar = "$" SqlPoint = "." SqlSpace = " " SqlStar = "*" SqlAs = "AS" SqlAsc = "ASC" SqlDesc = "DESC" SqlUnion = "UNION" SqlUnionAll = "UNION ALL" SqlJoinInner = "INNER JOIN" SqlJoinLeft = "LEFT JOIN" SqlJoinRight = "RIGHT JOIN" SqlJoinFull = "FULL JOIN" SqlAnd = "AND" SqlOr = "OR" SqlAvg = "AVG" SqlMax = "MAX" SqlMin = "MIN" SqlSum = "SUM" SqlCount = "COUNT" SqlNull = "NULL" SqlPlaceholder = "?" SqlEqual = "=" SqlNotEqual = "<>" SqlGreater = ">" SqlGreaterEqual = ">=" SqlLessThan = "<" SqlLessThanEqual = "<=" )
const ( AliasA = "a" AliasB = "b" AliasC = "c" AliasD = "d" AliasE = "e" AliasF = "f" AliasG = "g" )
const (
Id = "id"
)
Variables ¶
var ( DefaultConfig = &Config{ DeleteMustUseWhere: true, UpdateMustUseWhere: true, } )
var (
ErrNoAffectedRows = errors.New("hey: there are no affected rows")
)
Functions ¶
func ArgString ¶ added in v1.1.0
func ArgString(i interface{}) string
ArgString Convert SQL statement parameters into text strings.
func BasicTypeValue ¶ added in v1.1.0
func BasicTypeValue(value interface{}) interface{}
func ConcatString ¶ added in v1.1.0
ConcatString concatenate string
func EvenSlice2Map ¶ added in v1.2.0
func EvenSlice2Map[K comparable](elems ...K) map[K]K
EvenSlice2Map even slice to map
func LastNotEmptyString ¶ added in v1.1.0
LastNotEmptyString get last not empty string, return empty string if it does not exist
func MergeMap ¶ added in v1.2.0
func MergeMap[K comparable, V interface{}](elems ...map[K]V) map[K]V
MergeMap merge multiple maps
func MergeSlice ¶ added in v1.2.0
func MergeSlice[V interface{}](elems ...[]V) []V
MergeSlice merge multiple slices
func MustAffectedRows ¶ added in v1.2.0
MustAffectedRows at least one row is affected
func PrepareString ¶ added in v1.3.0
PrepareString Merge executed SQL statements and parameters.
func RemoveDuplicate ¶
func RemoveDuplicate(dynamic ...interface{}) (result []interface{})
RemoveDuplicate remove duplicate element
func RemoveDuplicates ¶ added in v1.1.0
func RemoveDuplicates[T comparable]( dynamic ...T, ) (result []T)
RemoveDuplicates remove duplicate element
func RemoveSliceMemberByIndex ¶ added in v1.1.1
func RemoveSliceMemberByIndex[T interface{}](indexList []int, elementList []T) []T
RemoveSliceMemberByIndex delete slice member by index
func ScanSliceStruct ¶
ScanSliceStruct Scan the query result set into the receiving object the receiving object type is *[]AnyStruct or *[]*AnyStruct.
func ScanViewMap ¶ added in v1.3.0
ScanViewMap Scan query result to []map[string]interface{}, view query result.
func Slice2MapNewKey ¶ added in v1.2.0
func Slice2MapNewKey[K comparable](elems []K, createKey func(v K) K) map[K]K
Slice2MapNewKey make map by slice, create key
func Slice2MapNewVal ¶ added in v1.2.0
func Slice2MapNewVal[K comparable, V interface{}](elems []K, createValue func(v K) V) map[K]V
Slice2MapNewVal make map by slice, create value
func SliceIter ¶ added in v1.2.0
func SliceIter[V interface{}](iter func(v V) V, elems []V) []V
SliceIter slice iteration
func SliceMatchMap ¶ added in v1.2.0
func SliceMatchMap[K comparable, X interface{}, Y interface{}](kx map[K]X, handle func(x X, y Y), key func(y Y) K, elems []Y)
SliceMatchMap use the `key` value of each element in `elems` to match in the map, and call `handle` if the match is successful
func StructInsert ¶ added in v1.0.1
func StructInsert(object interface{}, tag string, except []string, allow []string) (fields []string, values [][]interface{})
StructInsert object should be one of struct{}, *struct{}, []struct, []*struct{}, *[]struct{}, *[]*struct{} get fields and values based on struct tag.
func StructModify ¶
func StructModify(object interface{}, tag string, except ...string) (fields []string, values []interface{})
StructModify object should be one of struct{}, *struct{} get the fields and values that need to be modified
func StructObtain ¶ added in v1.1.0
func StructObtain(object interface{}, tag string, except ...string) (fields []string, values []interface{})
StructObtain object should be one of struct{}, *struct{} for get all fields and values
func StructUpdate ¶ added in v1.0.1
func StructUpdate(origin interface{}, latest interface{}, tag string, except ...string) (fields []string, values []interface{})
StructUpdate compare origin and latest for update
Types ¶
type Add ¶ added in v1.0.1
type Add struct {
// contains filtered or unexported fields
}
Add for INSERT
func (*Add) Create ¶ added in v1.0.1
Create value of create should be one of struct{}, *struct{}, map[string]interface{}, []struct, []*struct{}, *[]struct{}, *[]*struct{}
func (*Add) DefaultFieldValue ¶ added in v1.1.0
DefaultFieldValue append default field-value for insert one or more rows
func (*Add) FieldValue ¶ added in v1.1.0
FieldValue append field-value for insert one or more rows
func (*Add) Fields ¶ added in v1.1.0
Fields set fields, the current method resets the map field list and field index sequence
func (*Add) FieldsValues ¶ added in v1.1.0
FieldsValues set fields and values
func (*Add) OnConflict ¶ added in v1.1.0
OnConflict on conflict do something
func (*Add) ValuesSubQuery ¶ added in v1.0.1
ValuesSubQuery values is a query SQL statement
func (*Add) ValuesSubQueryGet ¶ added in v1.0.1
ValuesSubQueryGet values is a query SQL statement
type Caller ¶ added in v1.1.0
type Caller interface {
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Caller The implementation object is usually one of *sql.Conn, *sql.DB, *sql.Tx.
type Commander ¶ added in v1.3.0
type Commander interface {
// SQL Get the SQL statement that can be executed and its corresponding parameter list.
SQL() (prepare string, args []interface{})
}
type Config ¶ added in v1.1.0
type Config struct {
// DeleteMustUseWhere Deletion of data must be filtered using conditions.
DeleteMustUseWhere bool
// UpdateMustUseWhere Updated data must be filtered using conditions.
UpdateMustUseWhere bool
}
Config Configure of Way.
type Del ¶ added in v1.0.1
type Del struct {
// contains filtered or unexported fields
}
Del for DELETE
type Filter ¶
type Filter interface {
Copy(filter ...Filter) Filter
IsEmpty() bool
And(prepare string, args ...interface{}) Filter
Filter(filters ...Filter) Filter
Group(group func(filter Filter)) Filter
Equal(column string, value interface{}) Filter
Greater(column string, value interface{}) Filter
GreaterEqual(column string, value interface{}) Filter
LessThan(column string, value interface{}) Filter
LessThanEqual(column string, value interface{}) Filter
Between(column string, start interface{}, end interface{}) Filter
In(column string, values ...interface{}) Filter
InQuery(column string, fc func() (prepare string, args []interface{})) Filter
InGet(column string, cmd Commander) Filter
InCols(columns []string, values ...[]interface{}) Filter
InColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
InColsGet(columns []string, cmd Commander) Filter
Exists(fc func() (prepare string, args []interface{})) Filter
Like(column string, value interface{}) Filter
IsNull(column string) Filter
NotEqual(column string, value interface{}) Filter
NotBetween(column string, start interface{}, end interface{}) Filter
NotIn(column string, values ...interface{}) Filter
NotInQuery(column string, fc func() (prepare string, args []interface{})) Filter
NotInGet(column string, cmd Commander) Filter
NotInCols(columns []string, values ...[]interface{}) Filter
NotInColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
NotInColsGet(columns []string, cmd Commander) Filter
NotExists(fc func() (prepare string, args []interface{})) Filter
NotLike(column string, value interface{}) Filter
IsNotNull(column string) Filter
Or(prepare string, args ...interface{}) Filter
OrFilter(filters ...Filter) Filter
OrGroup(group func(filter Filter)) Filter
OrEqual(column string, value interface{}) Filter
OrGreater(column string, value interface{}) Filter
OrGreaterEqual(column string, value interface{}) Filter
OrLessThan(column string, value interface{}) Filter
OrLessThanEqual(column string, value interface{}) Filter
OrBetween(column string, start interface{}, end interface{}) Filter
OrIn(column string, values ...interface{}) Filter
OrInQuery(column string, fc func() (prepare string, args []interface{})) Filter
OrInGet(column string, cmd Commander) Filter
OrInCols(columns []string, values ...[]interface{}) Filter
OrInColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
OrInColsGet(columns []string, cmd Commander) Filter
OrExists(fc func() (prepare string, args []interface{})) Filter
OrLike(column string, value interface{}) Filter
OrIsNull(column string) Filter
OrNotEqual(column string, value interface{}) Filter
OrNotBetween(column string, start interface{}, end interface{}) Filter
OrNotIn(column string, values ...interface{}) Filter
OrNotInQuery(column string, fc func() (prepare string, args []interface{})) Filter
OrNotInGet(column string, cmd Commander) Filter
OrNotInCols(columns []string, values ...[]interface{}) Filter
OrNotInColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
OrNotInColsGet(columns []string, cmd Commander) Filter
OrNotExists(fc func() (prepare string, args []interface{})) Filter
OrNotLike(column string, value interface{}) Filter
OrIsNotNull(column string) Filter
SQL() (prepare string, args []interface{})
}
type Get ¶ added in v1.0.1
type Get struct {
// contains filtered or unexported fields
}
Get for SELECT
func (*Get) Alias ¶ added in v1.0.1
Alias for table alias name, don't forget to call the current method when the table is a SQL statement
func (*Get) AppendColumn ¶ added in v1.1.0
AppendColumn append the columns list of query
func (*Get) Count ¶ added in v1.0.1
Count execute the built SQL statement and scan query result for count
func (*Get) CountGet ¶ added in v1.1.0
CountGet execute the built SQL statement and scan query result, count + get
func (*Get) CountQuery ¶ added in v1.1.0
func (s *Get) CountQuery(query func(rows *sql.Rows) (err error), countColumn ...string) (int64, error)
CountQuery execute the built SQL statement and scan query result, count + query
func (*Get) Order ¶ added in v1.0.1
Order set the column sorting list in batches through regular expressions according to the request parameter value
func (*Get) ScanAll ¶ added in v1.3.0
ScanAll execute the built SQL statement and scan all from the query results.
func (*Get) ScanOne ¶ added in v1.3.0
ScanOne execute the built SQL statement and scan at most once from the query results.
func (*Get) SubQueryGet ¶ added in v1.1.0
SubQueryGet table is a query SQL statement
func (*Get) UnionAllGet ¶ added in v1.1.0
UnionAllGet union all query
func (*Get) ViewMap ¶ added in v1.3.0
ViewMap execute the built SQL statement and scan all from the query results.
type GetJoin ¶ added in v1.0.1
type GetJoin struct {
// contains filtered or unexported fields
}
GetJoin join SQL statement
func (*GetJoin) Alias ¶ added in v1.0.1
Alias for table alias name, don't forget to call the current method when the table is a SQL statement
func (*GetJoin) Column ¶ added in v1.3.1
Column Set the list of fields to be queried in the current table
func (*GetJoin) GetColumn ¶ added in v1.3.1
GetColumn Get the list of fields to be queried in the current table
func (*GetJoin) SubQueryGet ¶ added in v1.1.0
SubQueryGet table is a query SQL statement
type Ident ¶ added in v1.2.0
type Ident struct {
// contains filtered or unexported fields
}
Ident sql identifier
type LogArgs ¶ added in v1.1.0
type LogArgs struct {
// Args SQL parameter list.
Args []interface{}
// StartAt The start time of the SQL statement.
StartAt time.Time
// EndAt The end time of the SQL statement.
EndAt time.Time
}
LogArgs Record executed args of prepare.
type LogSQL ¶ added in v1.3.3
type LogSQL struct {
// TxId Transaction ID.
TxId string
// TxMsg Transaction descriptors.
TxMsg string
// Prepare Preprocess the SQL statements that are executed.
Prepare string
// Error An error encountered when executing SQL.
Error error
// Args SQL parameter list.
Args *LogArgs
}
LogSQL Record executed prepare args.
type LogTrans ¶ added in v1.3.3
type LogTrans struct {
// Transaction id.
TxId string
// Transaction message.
TxMsg string
// Transaction start at.
StartAt time.Time
// Transaction end at.
EndAt time.Time
// Transaction result COMMIT || ROLLBACK.
State string
// Error.
Error error
}
LogTrans Record executed transaction.
type Mod ¶ added in v1.0.1
type Mod struct {
// contains filtered or unexported fields
}
Mod for UPDATE
func (*Mod) DefaultDecr ¶ added in v1.1.0
DefaultDecr SET field = field - value
func (*Mod) DefaultExpr ¶ added in v1.1.0
DefaultExpr update field using custom expression
func (*Mod) DefaultIncr ¶ added in v1.1.0
DefaultIncr SET field = field + value
func (*Mod) DefaultSet ¶ added in v1.1.0
DefaultSet SET field = value
func (*Mod) FieldsValues ¶ added in v1.1.0
FieldsValues SET field = value by slice, require len(fields) == len(values)
func (*Mod) Modify ¶ added in v1.1.0
Modify value of modify should be one of struct{}, *struct{}, map[string]interface{}
type Opts ¶ added in v1.1.0
type Opts func(s *Way)
Opts Custom attribute value of *Way.
func WithConfig ¶ added in v1.1.0
WithConfig -> Uses custom configure.
func WithLogger ¶ added in v1.1.0
WithLogger -> Uses custom logger.
func WithPrepare ¶ added in v1.1.0
WithPrepare -> Uses custom fix prepare.
func WithReader ¶ added in v1.3.0
WithReader -> uses reader for query.
func WithTxLogger ¶ added in v1.1.0
WithTxLogger -> Uses custom transaction logger.
func WithTxOpts ¶ added in v1.1.0
WithTxOpts -> Uses custom global default transaction isolation level.
type PrepareArgs ¶ added in v1.1.0
type PrepareArgs struct {
Prepare string
Args []interface{}
}
PrepareArgs Statements to be executed and corresponding parameter list.
type Reader ¶ added in v1.3.0
type Reader interface {
// Read Get an object for read.
Read() *Way
}
Reader Separate read and write, when you distinguish between reading and writing, please do not use the same object for both reading and writing.
type Stmt ¶ added in v1.1.0
type Stmt struct {
// contains filtered or unexported fields
}
Stmt Prepare handle.
func (*Stmt) Exec ¶ added in v1.1.0
Exec -> Execute prepared, that can be called repeatedly, return number of rows affected.
func (*Stmt) ExecContext ¶ added in v1.1.0
ExecContext -> Execute prepared, that can be called repeatedly, return number of rows affected.
func (*Stmt) ExecuteContext ¶ added in v1.2.1
ExecuteContext -> Execute prepared, that can be called repeatedly.
func (*Stmt) QueryContext ¶ added in v1.1.0
func (s *Stmt) QueryContext(ctx context.Context, query func(rows *sql.Rows) error, args ...interface{}) error
QueryContext -> Query prepared, that can be called repeatedly.
func (*Stmt) QueryRowContext ¶ added in v1.2.1
func (s *Stmt) QueryRowContext(ctx context.Context, query func(rows *sql.Row) error, args ...interface{}) error
QueryRowContext -> Query prepared, that can be called repeatedly.
type SubQuery ¶
type SubQuery struct {
// contains filtered or unexported fields
}
func NewSubQuery ¶ added in v1.0.1
type TxArgs ¶ added in v1.3.0
type TxArgs struct {
// Use the specified database connection, default nil.
Conn *sql.Conn
// Use the specified transaction isolation level, default *Way.txOpts.
Opts *sql.TxOptions
// Try calling transaction multiple times, default 1.
Times int
}
TxArgs Optional args for begin a transaction.
type Way ¶
type Way struct {
// contains filtered or unexported fields
}
Way Quick insert, delete, update, select helper.
func (*Way) ExecContext ¶
ExecContext -> Execute the execute sql statement.
func (*Way) ExecuteContext ¶ added in v1.2.1
func (s *Way) ExecuteContext(ctx context.Context, prepare string, args ...interface{}) (sql.Result, error)
ExecuteContext -> Execute the execute sql statement.
func (*Way) Getter ¶ added in v1.1.0
Getter -> Execute the query sql statement without args, no prepared is used.
func (*Way) GetterContext ¶ added in v1.1.0
func (s *Way) GetterContext(ctx context.Context, query func(rows *sql.Rows) error, prepare string, caller ...Caller) (err error)
GetterContext -> Execute the query sql statement without args, no prepared is used.
func (*Way) Now ¶ added in v1.1.0
Now -> Get current time, the transaction open status will get the same time.
func (*Way) PrepareContext ¶ added in v1.1.0
PrepareContext -> Prepare sql statement, don't forget to call *Stmt.Close().
func (*Way) QueryContext ¶
func (s *Way) QueryContext(ctx context.Context, query func(rows *sql.Rows) error, prepare string, args ...interface{}) error
QueryContext -> Execute the query sql statement.
func (*Way) QueryRow ¶ added in v1.2.1
QueryRow -> Execute sql statement and return a row data, usually INSERT, UPDATE, DELETE.
func (*Way) QueryRowContext ¶ added in v1.2.1
func (s *Way) QueryRowContext(ctx context.Context, query func(row *sql.Row) error, prepare string, args ...interface{}) error
QueryRowContext -> Execute sql statement and return a row data, usually INSERT, UPDATE, DELETE.
func (*Way) Setter ¶ added in v1.1.0
Setter -> Execute the execute sql statement without args, no prepared is used.
func (*Way) SetterContext ¶ added in v1.1.0
SetterContext -> Execute the execute sql statement without args, no prepared is used.
func (*Way) TakeAllContext ¶ added in v1.3.0
func (s *Way) TakeAllContext(ctx context.Context, result interface{}, prepare string, args ...interface{}) error
TakeAllContext -> Query prepared and get all query results, through the mapping of column names and struct tags.
func (*Way) TxMsg ¶ added in v1.1.0
TxMsg -> Set the prompt for the current transaction, can only be set once.
type WindowFunc ¶ added in v1.3.1
type WindowFunc struct {
// contains filtered or unexported fields
}
WindowFunc SQL window function.
func NewWindowFunc ¶ added in v1.3.1
func NewWindowFunc(alias ...string) *WindowFunc
func (*WindowFunc) Alias ¶ added in v1.3.1
func (s *WindowFunc) Alias(alias string) *WindowFunc
Alias Set the alias of the field that uses the window function.
func (*WindowFunc) Asc ¶ added in v1.3.1
func (s *WindowFunc) Asc(column string) *WindowFunc
Asc Define the sorting within the partition so that the window function is calculated in order.
func (*WindowFunc) Avg ¶ added in v1.3.1
func (s *WindowFunc) Avg(column string) *WindowFunc
Avg AVG() Returns the average of all rows in the window.
func (*WindowFunc) Count ¶ added in v1.3.1
func (s *WindowFunc) Count(column string) *WindowFunc
Count COUNT() Returns the number of rows in the window.
func (*WindowFunc) DenseRank ¶ added in v1.3.1
func (s *WindowFunc) DenseRank() *WindowFunc
DenseRank DENSE_RANK() Similar to RANK(), but does not skip rankings.
func (*WindowFunc) Desc ¶ added in v1.3.1
func (s *WindowFunc) Desc(column string) *WindowFunc
Desc Define the sorting within the partition so that the window function is calculated in descending order.
func (*WindowFunc) FirstValue ¶ added in v1.3.1
func (s *WindowFunc) FirstValue(column string) *WindowFunc
FirstValue FIRST_VALUE() Returns the value of the first row in the window.
func (*WindowFunc) Lag ¶ added in v1.3.1
func (s *WindowFunc) Lag(column string, offset int64, defaultValue any) *WindowFunc
Lag LAG() Returns the value of the row before the current row.
func (*WindowFunc) LastValue ¶ added in v1.3.1
func (s *WindowFunc) LastValue(column string) *WindowFunc
LastValue LAST_VALUE() Returns the value of the last row in the window.
func (*WindowFunc) Lead ¶ added in v1.3.1
func (s *WindowFunc) Lead(column string, offset int64, defaultValue any) *WindowFunc
Lead LEAD() Returns the value of a row after the current row.
func (*WindowFunc) Max ¶ added in v1.3.1
func (s *WindowFunc) Max(column string) *WindowFunc
Max MAX() Returns the maximum value within the window.
func (*WindowFunc) Min ¶ added in v1.3.1
func (s *WindowFunc) Min(column string) *WindowFunc
Min MIN() Returns the minimum value within the window.
func (*WindowFunc) NthValue ¶ added in v1.3.1
func (s *WindowFunc) NthValue(column string, LineNumber int64) *WindowFunc
NthValue NTH_VALUE() The Nth value can be returned according to the specified order. This is very useful when you need to get data at a specific position.
func (*WindowFunc) Ntile ¶ added in v1.3.1
func (s *WindowFunc) Ntile(buckets int64) *WindowFunc
Ntile NTILE() Divide the rows in the window into n buckets and assign a bucket number to each row.
func (*WindowFunc) Partition ¶ added in v1.3.1
func (s *WindowFunc) Partition(column ...string) *WindowFunc
Partition The OVER clause defines window partitions so that the window function is calculated independently in each partition.
func (*WindowFunc) Rank ¶ added in v1.3.1
func (s *WindowFunc) Rank() *WindowFunc
Rank RANK() Assign a rank to each row, if there are duplicate values, the rank is skipped.
func (*WindowFunc) Result ¶ added in v1.3.1
func (s *WindowFunc) Result() string
Result Query column expressions.
func (*WindowFunc) RowNumber ¶ added in v1.3.1
func (s *WindowFunc) RowNumber() *WindowFunc
RowNumber ROW_NUMBER() Assign a unique serial number to each row, in the order specified, starting with 1.
func (*WindowFunc) Sum ¶ added in v1.3.1
func (s *WindowFunc) Sum(column string) *WindowFunc
Sum SUM() Returns the sum of all rows in the window.
func (*WindowFunc) WindowFrame ¶ added in v1.3.1
func (s *WindowFunc) WindowFrame(windowFrame string) *WindowFunc
WindowFrame Set custom window frame clause.
func (*WindowFunc) WithFunc ¶ added in v1.3.1
func (s *WindowFunc) WithFunc(withFunc string) *WindowFunc
WithFunc Using custom function. for example: CUME_DIST(), PERCENT_RANK(), PERCENTILE_CONT(), PERCENTILE_DISC()...