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 LastNotEmptyString(sss []string) string
- func PrepareArgs(prepare string, args []interface{}) string
- func RemoveDuplicate(dynamic ...interface{}) (result []interface{})
- func RemoveDuplicates[...](dynamic ...T) (result []T)
- func RemoveSliceMemberByIndex[...](indexList []int, elementList []T) []T
- func RowsNext(rows *sql.Rows, fc func() error) (err error)
- func RowsNextRow(rows *sql.Rows, dest ...interface{}) error
- func ScanSliceStruct(rows *sql.Rows, result interface{}, tag string) error
- func SliceAny121(values ...interface{}) []interface{}
- func SqlAlias(name string, alias string) string
- func SqlPrefix(prefix string, name string) string
- func StructInsert(object interface{}, tag string, except ...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{})
- func ValuesIn[...](values ...T) []interface{}deprecated
- func ValuesInGroup[...](values ...[]T) [][]interface{}deprecated
- 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) SQL() (prepare string, args []interface{})
- func (s *Add) Table(table string) *Add
- func (s *Add) Values(values [][]interface{}) *Add
- func (s *Add) ValuesSubQuery(prepare string, args ...interface{}) *Add
- func (s *Add) ValuesSubQueryGet(get *Get) *Add
- type Caller
- type Config
- type 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) 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) *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) RowsNextRow(dest ...interface{}) error
- func (s *Get) SQL() (prepare string, args []interface{})
- func (s *Get) SQLCount(columns ...string) (prepare string, args []interface{})
- 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) 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) 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 Identifier
- func (s *Identifier) Avg(field string, alias ...string) string
- func (s *Identifier) Avg1(field string) string
- func (s *Identifier) Count(field string, alias ...string) string
- func (s *Identifier) Max(field string, alias ...string) string
- func (s *Identifier) Max1(field string) string
- func (s *Identifier) Min(field string, alias ...string) string
- func (s *Identifier) Min1(field string) string
- func (s *Identifier) Sum(field string, alias ...string) string
- func (s *Identifier) Sum1(field string) string
- func (s *Identifier) V(sss ...string) string
- type Limiter
- type LogArgs
- type LogPrepareArgs
- type LogTransaction
- 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) 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) Where(where Filter) *Mod
- type Opts
- type Pgsql
- type Preparer
- 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{}) (rowsAffected int64, err 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{}) (err error)
- func (s *Stmt) ScanAll(result interface{}, args ...interface{}) error
- func (s *Stmt) ScanAllContext(ctx context.Context, result interface{}, args ...interface{}) error
- type SubQuery
- type Way
- func (s *Way) Add(table string) *Add
- 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) 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) Identifier(prefix ...string) *Identifier
- 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) RowsNext(rows *sql.Rows, fc func() error) error
- func (s *Way) RowsNextRow(rows *sql.Rows, dest ...interface{}) error
- func (s *Way) ScanAll(result interface{}, prepare string, args ...interface{}) error
- func (s *Way) ScanAllContext(ctx context.Context, result interface{}, prepare string, args ...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) Tx(fc func(tx *Way) error, conn ...*sql.Conn) error
- func (s *Way) TxCtx(ctx context.Context, fc func(tx *Way) error, conn ...*sql.Conn) error
- func (s *Way) TxMsg(msg string) *Way
- func (s *Way) TxNil() bool
- func (s *Way) TxTry(fc func(tx *Way) error, times int, conn ...*sql.Conn) error
- func (s *Way) TxTryCtx(ctx context.Context, fc func(tx *Way) error, times int, conn ...*sql.Conn) (err error)
- type WayWriterReader
- type WithQuery
Constants ¶
const ( SqlAs = "AS" SqlAsc = "ASC" SqlDesc = "DESC" SqlUnion = "UNION" SqlUnionAll = "UNION ALL" )
const ( SqlJoinInner = "INNER JOIN" SqlJoinLeft = "LEFT JOIN" SqlJoinRight = "RIGHT JOIN" SqlJoinFull = "FULL JOIN" )
const (
// DefaultTag mapping of default database column name and struct tag
DefaultTag = "db"
)
const (
Dollar = "$"
)
const (
Placeholder = "?"
)
const (
Point = "."
)
Variables ¶
var ( DefaultConfig = &Config{ DeleteMustUseWhere: true, UpdateMustUseWhere: true, } )
var (
DefaultPgsql = &Pgsql{}
)
Functions ¶
func BasicTypeValue ¶ added in v1.1.0
func BasicTypeValue(value interface{}) interface{}
func ConcatString ¶ added in v1.1.0
ConcatString concatenate string
func LastNotEmptyString ¶ added in v1.1.0
LastNotEmptyString get last not empty string, return empty string if it does not exist
func PrepareArgs ¶ added in v1.1.0
func RemoveDuplicate ¶
func RemoveDuplicate(dynamic ...interface{}) (result []interface{})
RemoveDuplicate remove duplicate element
func RemoveDuplicates ¶ added in v1.1.0
func RemoveDuplicates[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | string]( dynamic ...T, ) (result []T)
RemoveDuplicates remove duplicate element
func RemoveSliceMemberByIndex ¶ added in v1.1.1
func RemoveSliceMemberByIndex[T bool | int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | float32 | float64 | string | interface{}](indexList []int, elementList []T) []T
RemoveSliceMemberByIndex delete slice member by index
func RowsNextRow ¶ added in v1.1.0
RowsNextRow scan one line of query results
func ScanSliceStruct ¶
ScanSliceStruct Scan the query result set into the receiving object the receiving object type is *[]AnyStruct or *[]*AnyStruct.
func SliceAny121 ¶ added in v1.1.2
func SliceAny121(values ...interface{}) []interface{}
func StructInsert ¶ added in v1.0.1
func StructInsert(object interface{}, tag string, except ...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 customize default field-value for insert one or more rows
func (*Add) FieldValue ¶ added in v1.1.0
FieldValue add field-value for insert one or more rows
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 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
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, preparer Preparer) Filter
// Deprecated: please use Filter.In instead
InInt(column string, values []int) Filter
// Deprecated: please use Filter.In instead
InInt64(column string, values []int64) Filter
// Deprecated: please use Filter.In instead
InString(column string, values []string) Filter
InCols(columns []string, values ...[]interface{}) Filter
InColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
InColsGet(columns []string, preparer Preparer) 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, preparer Preparer) Filter
// Deprecated: please use Filter.In instead
NotInInt(column string, values []int) Filter
// Deprecated: please use Filter.In instead
NotInInt64(column string, values []int64) Filter
// Deprecated: please use Filter.In instead
NotInString(column string, values []string) Filter
NotInCols(columns []string, values ...[]interface{}) Filter
NotInColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
NotInColsGet(columns []string, preparer Preparer) 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, preparer Preparer) Filter
// Deprecated: please use Filter.In instead
OrInInt(column string, values []int) Filter
// Deprecated: please use Filter.In instead
OrInInt64(column string, values []int64) Filter
// Deprecated: please use Filter.In instead
OrInString(column string, values []string) Filter
OrInCols(columns []string, values ...[]interface{}) Filter
OrInColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
OrInColsGet(columns []string, preparer Preparer) 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, preparer Preparer) Filter
// Deprecated: please use Filter.In instead
OrNotInInt(column string, values []int) Filter
// Deprecated: please use Filter.In instead
OrNotInInt64(column string, values []int64) Filter
// Deprecated: please use Filter.In instead
OrNotInString(column string, values []string) Filter
OrNotInCols(columns []string, values ...[]interface{}) Filter
OrNotInColsQuery(columns []string, fc func() (prepare string, args []interface{})) Filter
OrNotInColsGet(columns []string, preparer Preparer) 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) RowsNextRow ¶ added in v1.1.0
RowsNextRow execute the built SQL statement and scan query result, only scan one row
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
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) SubQueryGet ¶ added in v1.1.0
SubQueryGet table is a query SQL statement
type Identifier ¶ added in v1.1.0
type Identifier struct {
// contains filtered or unexported fields
}
Identifier sql identifier
func (*Identifier) Avg ¶ added in v1.1.0
func (s *Identifier) Avg(field string, alias ...string) string
func (*Identifier) Avg1 ¶ added in v1.1.0
func (s *Identifier) Avg1(field string) string
func (*Identifier) Count ¶ added in v1.1.0
func (s *Identifier) Count(field string, alias ...string) string
func (*Identifier) Max ¶ added in v1.1.0
func (s *Identifier) Max(field string, alias ...string) string
func (*Identifier) Max1 ¶ added in v1.1.0
func (s *Identifier) Max1(field string) string
func (*Identifier) Min ¶ added in v1.1.0
func (s *Identifier) Min(field string, alias ...string) string
func (*Identifier) Min1 ¶ added in v1.1.0
func (s *Identifier) Min1(field string) string
func (*Identifier) Sum ¶ added in v1.1.0
func (s *Identifier) Sum(field string, alias ...string) string
func (*Identifier) Sum1 ¶ added in v1.1.0
func (s *Identifier) Sum1(field string) string
func (*Identifier) V ¶ added in v1.1.0
func (s *Identifier) V(sss ...string) string
V identifier value
type LogPrepareArgs ¶ added in v1.1.0
LogPrepareArgs record executed prepare args
type LogTransaction ¶ added in v1.1.0
type LogTransaction struct {
TxId string // transaction id
TxMsg string // transaction message
StartAt time.Time // transaction start at
EndAt time.Time // transaction end at
State string // transaction result COMMIT || ROLLBACK
Error error // error
}
LogTransaction 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
func WithLogger(log func(log *LogPrepareArgs)) Opts
WithLogger -> uses custom logger
func WithPrepare ¶ added in v1.1.0
WithPrepare -> uses custom fix prepare
func WithTxLogger ¶ added in v1.1.0
func WithTxLogger(txLog func(log *LogTransaction)) Opts
WithTxLogger -> uses custom transaction logger
func WithTxOpts ¶ added in v1.1.0
WithTxOpts -> uses custom global default transaction isolation level
type Pgsql ¶ added in v1.1.0
type Pgsql struct{}
func (*Pgsql) CloneTableStruct ¶ added in v1.1.0
func (s *Pgsql) CloneTableStruct( dst string, src string, seq string, ) ( create []string, drop []string, )
CloneTableStruct clone table structure
type Preparer ¶ added in v1.1.0
type Preparer interface {
// SQL get the prepare sql statement and parameter list
SQL() (prepare string, args []interface{})
}
type Stmt ¶ added in v1.1.0
type Stmt struct {
// contains filtered or unexported fields
}
Stmt prepare handle
func (*Stmt) ExecContext ¶ added in v1.1.0
func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (rowsAffected int64, err error)
ExecContext -> 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{}) (err error)
QueryContext -> 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 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) 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) Identifier ¶ added in v1.1.0
func (s *Way) Identifier(prefix ...string) *Identifier
Identifier -> sql identifier
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) RowsNextRow ¶ added in v1.1.0
RowsNextRow -> scan one line of query results
func (*Way) ScanAllContext ¶ added in v1.1.0
func (s *Way) ScanAllContext(ctx context.Context, result interface{}, prepare string, args ...interface{}) error
ScanAllContext -> query and scan results through the mapping of column names and struct tags
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) TxMsg ¶ added in v1.1.0
TxMsg -> set the prompt for the current transaction, can only be set once
type WayWriterReader ¶ added in v1.1.0
type WayWriterReader interface {
// W get an object for write
W() *Way
// R get an object for read
R() *Way
}
WayWriterReader -> read and write separation
func NewWayWriterReader ¶ added in v1.1.0
func NewWayWriterReader( choose func(n int) int, writer []*Way, reader []*Way, ) (WayWriterReader, error)
NewWayWriterReader -> read and write separated calls