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
- func ArrayRemoveIndex[V interface{}](values []V, indexes []int) []V
- func ArrayToArray[V interface{}, W interface{}](values []V, fc func(v V) W) []W
- func ArrayToAssoc[V interface{}, K comparable, W interface{}](values []V, fc func(v V) (K, W)) map[K]W
- func AssocToArray[K comparable, V interface{}, W interface{}](values map[K]V, fc func(k K, v V) W) []W
- func CmderGet(ctx context.Context, way *Way, cmder Cmder, result interface{}) error
- func CmderGetCmd(s *Get) (prepare string, args []interface{})
- func CmderGetCount(s *Get, countColumns ...string) (prepare string, args []interface{})
- func CmderGetOrderLimitOffset(s *Get) (prepare string, args []interface{})
- func CmderGetTable(s *Get) (prepare string, args []interface{})
- func CmderQuery(ctx context.Context, way *Way, cmder Cmder, ...) error
- func CmderScanAll(ctx context.Context, way *Way, cmder Cmder, custom func(rows *sql.Rows) error) error
- func CmderScanOne(ctx context.Context, way *Way, cmder Cmder, dest ...interface{}) error
- func CmderViewMap(ctx context.Context, way *Way, cmder Cmder) (result []map[string]interface{}, err error)
- func ColumnInValues[T interface{}](values []T, fc func(tmp T) interface{}) []interface{}
- func ColumnsInValues[T interface{}](values []T, fc func(tmp T) []interface{}) [][]interface{}
- func ConcatString(sss ...string) string
- func GetCount(get *Get, countColumns ...string) (count int64, err error)
- func GetCountGet(get *Get, result interface{}, countColumn ...string) (int64, error)
- func GetCountQuery(get *Get, query func(rows *sql.Rows) (err error), countColumn ...string) (int64, error)
- func GetExists(get *Get) (exists bool, err error)
- func GetGet(get *Get, result interface{}) error
- func GetQuery(get *Get, query func(rows *sql.Rows) (err error)) error
- func GetScanAll(get *Get, fc func(rows *sql.Rows) error) error
- func GetScanOne(get *Get, dest ...interface{}) error
- func GetViewMap(get *Get) (result []map[string]interface{}, err error)
- func IsEmptyCmder(cmder Cmder) bool
- func LastNotEmptyString(sss []string) string
- func MergeArray[V interface{}](values ...[]V) []V
- func MergeAssoc[K comparable, V interface{}](values ...map[K]V) map[K]V
- func MustAffectedRows(affectedRows int64, err error) error
- func NullDefaultValue(prepare string, defaultValue string) string
- func ParcelCancelPrepare(prepare string) string
- func ParcelPrepare(prepare string) string
- func PutFilter(f Filter)
- func RemoveDuplicate(dynamic ...interface{}) (result []interface{})
- func RemoveDuplicates[T comparable](dynamic ...T) (result []T)
- func RowsScanStructAll[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, ...) ([]*V, error)
- func RowsScanStructAllCmder[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, ...) ([]*V, error)
- func RowsScanStructOne[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, ...) (*V, error)
- func RowsScanStructOneCmder[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, ...) (*V, error)
- 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 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) AddOne(custom func(add AddOneReturnSequenceValue)) (int64, error)
- func (s *Add) Cmd() (prepare string, args []interface{})
- func (s *Add) CmderValues(cmdValues Cmder, columns []string) *Add
- func (s *Add) ColumnValue(column string, value interface{}) *Add
- func (s *Add) ColumnsValues(columns []string, values [][]interface{}) *Add
- 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) Default(add func(add *Add)) *Add
- func (s *Add) ExceptPermit(custom func(except UpsertColumns, permit UpsertColumns)) *Add
- func (s *Add) GetColumns() []string
- func (s *Add) GetContext() context.Context
- func (s *Add) GetValues() [][]interface{}
- func (s *Add) GetWay() *Way
- func (s *Add) Table(table string) *Add
- type AddOneReturnSequenceValue
- type Caller
- type Cfg
- type Cmder
- func ConcatCmder(concat string, custom func(index int, cmder Cmder) Cmder, items ...Cmder) Cmder
- func ExceptCmder(items ...Cmder) Cmder
- func IntersectCmder(items ...Cmder) Cmder
- func NewCmder(prepare string, args []interface{}) Cmder
- func ParcelCancelCmder(cmder Cmder) Cmder
- func ParcelCmder(cmder Cmder) Cmder
- func UnionAllCmder(items ...Cmder) Cmder
- func UnionCmder(items ...Cmder) Cmder
- type Debugger
- type Del
- func (s *Del) Cmd() (prepare string, args []interface{})
- func (s *Del) Comment(comment string) *Del
- func (s *Del) Context(ctx context.Context) *Del
- func (s *Del) Del() (int64, error)
- func (s *Del) GetContext() context.Context
- func (s *Del) GetWay() *Way
- func (s *Del) Table(table string, args ...interface{}) *Del
- func (s *Del) TableCmder(cmder TableCmder) *Del
- func (s *Del) Where(where func(f Filter)) *Del
- type ErrorNoRowsAffected
- type ErrorRecordDoesNotExists
- type ErrorTransactionNotStarted
- type Filter
- type Get
- func (s *Get) Alias(alias string) *Get
- func (s *Get) Asc(column string) *Get
- func (s *Get) Cmd() (prepare string, args []interface{})
- func (s *Get) Comment(comment string) *Get
- func (s *Get) Context(ctx context.Context) *Get
- func (s *Get) Count(column ...string) (int64, error)
- func (s *Get) CountCmd(columns ...string) (string, []interface{})
- 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() (bool, error)
- func (s *Get) Get(result interface{}) error
- func (s *Get) GetContext() context.Context
- func (s *Get) GetSelect() QueryColumns
- func (s *Get) GetWay() *Way
- func (s *Get) Group(group ...string) *Get
- func (s *Get) Having(having func(f Filter)) *Get
- func (s *Get) Join(custom func(join QueryJoin)) *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) ScanAll(fc func(rows *sql.Rows) error) error
- func (s *Get) ScanOne(dest ...interface{}) error
- func (s *Get) Select(columns ...string) *Get
- func (s *Get) SetSelect(queryColumns QueryColumns) *Get
- func (s *Get) Subquery(subquery Cmder, alias string) *Get
- func (s *Get) Table(table string) *Get
- func (s *Get) ViewMap() ([]map[string]interface{}, error)
- func (s *Get) Where(where func(f Filter)) *Get
- func (s *Get) With(alias string, script Cmder) *Get
- type InsertOnConflict
- type InsertOnConflictUpdateSet
- type InsertValue
- type IsEmpty
- type JoinCondition
- type Limiter
- type Manual
- type Mod
- func (s *Mod) Cmd() (prepare string, args []interface{})
- func (s *Mod) ColumnsValues(columns []string, values []interface{}) *Mod
- func (s *Mod) Comment(comment string) *Mod
- func (s *Mod) Compare(old, new interface{}, except ...string) *Mod
- func (s *Mod) Context(ctx context.Context) *Mod
- func (s *Mod) Decr(column string, value interface{}) *Mod
- func (s *Mod) Default(custom func(mod *Mod)) *Mod
- func (s *Mod) ExceptPermit(custom func(except UpsertColumns, permit UpsertColumns)) *Mod
- func (s *Mod) Expr(expr string, args ...interface{}) *Mod
- func (s *Mod) GetContext() context.Context
- func (s *Mod) GetUpdateSet() (prepare string, args []interface{})
- func (s *Mod) GetWay() *Way
- func (s *Mod) Incr(column string, value interface{}) *Mod
- func (s *Mod) Mod() (int64, error)
- func (s *Mod) Set(column string, value interface{}) *Mod
- func (s *Mod) Table(table string, args ...interface{}) *Mod
- func (s *Mod) Update(update interface{}) *Mod
- func (s *Mod) Where(where func(f Filter)) *Mod
- type Quantifier
- type QueryColumns
- type QueryGroup
- type QueryJoin
- type QueryLimit
- type QueryOrder
- type QueryWith
- type Reader
- type Replace
- 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 TableCmder
- type TableColumn
- func (s *TableColumn) AVG(column string, aliases ...string) string
- func (s *TableColumn) Adjust(adjust func(column string) string, columns ...string) []string
- func (s *TableColumn) Alias() string
- func (s *TableColumn) Avg(column string, aliases ...string) string
- func (s *TableColumn) Column(column string, aliases ...string) string
- func (s *TableColumn) ColumnAll(columns ...string) []string
- func (s *TableColumn) Count(counts ...string) string
- func (s *TableColumn) MAX(column string, aliases ...string) string
- func (s *TableColumn) MIN(column string, aliases ...string) string
- func (s *TableColumn) Max(column string, aliases ...string) string
- func (s *TableColumn) Min(column string, aliases ...string) string
- func (s *TableColumn) SUM(column string, aliases ...string) string
- func (s *TableColumn) SetAlias(alias string) *TableColumn
- func (s *TableColumn) Sum(column string, aliases ...string) string
- type UpdateSet
- type UpsertColumns
- type Way
- func (s *Way) Add(table string) *Add
- func (s *Way) BatchUpdate(prepare string, argsList [][]interface{}) (affectedRows int64, err error)
- func (s *Way) BatchUpdateContext(ctx context.Context, prepare string, argsList [][]interface{}) (affectedRows int64, err error)
- func (s *Way) Begin(ctx context.Context, opts ...*sql.TxOptions) (*Way, error)
- func (s *Way) BeginConn(ctx context.Context, conn *sql.Conn, opts ...*sql.TxOptions) (*Way, error)
- func (s *Way) CmderExec(cmder Cmder) (int64, error)
- func (s *Way) CmderExecContext(ctx context.Context, cmder Cmder) (int64, error)
- func (s *Way) CmderExecute(cmder Cmder) (sql.Result, error)
- func (s *Way) CmderExecuteContext(ctx context.Context, cmder Cmder) (sql.Result, error)
- func (s *Way) CmderQuery(cmder Cmder, query func(rows *sql.Rows) error) error
- func (s *Way) CmderQueryContext(ctx context.Context, cmder Cmder, query func(rows *sql.Rows) error) error
- func (s *Way) CmderQueryRow(cmder Cmder, query func(row *sql.Row) error) error
- func (s *Way) CmderQueryRowContext(ctx context.Context, cmder Cmder, query func(row *sql.Row) error) error
- func (s *Way) CmderTakeAll(cmder Cmder, result interface{}) error
- func (s *Way) CmderTakeAllContext(ctx context.Context, cmder Cmder, result interface{}) error
- func (s *Way) Commit() error
- func (s *Way) Debugger(cmder Cmder) *Way
- 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(fs ...Filter) Filter
- func (s *Way) Get(table ...string) *Get
- func (s *Way) GetCfg() *Cfg
- func (s *Way) GetDatabase() *sql.DB
- func (s *Way) GetLogger() *logger.Logger
- func (s *Way) GetReader() Reader
- func (s *Way) Getter(caller Caller, query func(rows *sql.Rows) error, prepare string, ...) error
- func (s *Way) GetterContext(ctx context.Context, caller Caller, query func(rows *sql.Rows) error, ...) (err error)
- func (s *Way) IsInTransaction() bool
- func (s *Way) IsRead() bool
- func (s *Way) Mod(table string) *Mod
- func (s *Way) NewAddOne(prepare string, args []interface{}) AddOneReturnSequenceValue
- 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 *Stmt, err 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) Replace(key string) string
- func (s *Way) Replaces(keys []string) []string
- func (s *Way) Rollback() error
- 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) SetCfg(cfg *Cfg) *Way
- func (s *Way) SetDatabase(db *sql.DB) *Way
- func (s *Way) SetLogger(l *logger.Logger) *Way
- func (s *Way) SetReader(reader Reader) *Way
- func (s *Way) Setter(caller Caller, prepare string, args ...interface{}) (int64, error)
- func (s *Way) SetterContext(ctx context.Context, caller Caller, prepare string, args ...interface{}) (int64, error)
- func (s *Way) T() *TableColumn
- func (s *Way) TA() *TableColumn
- func (s *Way) TB() *TableColumn
- func (s *Way) TC() *TableColumn
- func (s *Way) TD() *TableColumn
- func (s *Way) TE() *TableColumn
- func (s *Way) TF() *TableColumn
- func (s *Way) TG() *TableColumn
- 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) Transaction(ctx context.Context, fc func(tx *Way) error, opts ...*sql.TxOptions) error
- func (s *Way) TransactionMessage(message string) *Way
- func (s *Way) TransactionNew(ctx context.Context, fc func(tx *Way) error, opts ...*sql.TxOptions) error
- func (s *Way) TransactionRetry(ctx context.Context, retries int, fc func(tx *Way) error, ...) (err error)
- func (s *Way) WindowFunc(alias ...string) *WindowFunc
- 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
Constants ¶
const ( State0 = 0 State1 = 1 StateY = "Y" StateN = "N" StateYes = "YES" StateNo = "NO" StateOn = "ON" StateOff = "OFF" )
Common data values for table.column.
const ( // DefaultTag Mapping of default database column name and struct tag. DefaultTag = "db" // EmptyString Empty string value. EmptyString = "" )
const ( SqlConcat = ", " 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" SqlJoinCross = "CROSS JOIN" SqlAnd = "AND" SqlOr = "OR" SqlNot = "NOT" SqlNull = "NULL" SqlPlaceholder = "?" SqlEqual = "=" SqlNotEqual = "<>" SqlGreaterThan = ">" SqlGreaterThanEqual = ">=" SqlLessThan = "<" SqlLessThanEqual = "<=" SqlAll = "ALL" SqlAny = "ANY" SqlSome = "SOME" SqlLeftSmallBracket = "(" SqlRightSmallBracket = ")" SqlExpect = "EXCEPT" SqlIntersect = "INTERSECT" SqlCoalesce = "COALESCE" SqlDistinct = "DISTINCT" )
const ( AliasA = "a" AliasB = "b" AliasC = "c" AliasD = "d" AliasE = "e" AliasF = "f" AliasG = "g" )
const ( // RecordDoesNotExists record does not exist. RecordDoesNotExists = ErrorRecordDoesNotExists("database: record does not exist") // NoRowsAffected no rows affected. NoRowsAffected = ErrorNoRowsAffected("database: no rows affected") // TransactionNotStarted transaction not started. TransactionNotStarted = ErrorTransactionNotStarted("database: transaction not started") )
const (
DefaultAliasNameCount = "counts"
)
Variables ¶
This section is empty.
Functions ¶
func ArrayRemoveIndex ¶
func ArrayRemoveIndex[V interface{}](values []V, indexes []int) []V
func ArrayToArray ¶
func ArrayToArray[V interface{}, W interface{}](values []V, fc func(v V) W) []W
func ArrayToAssoc ¶
func ArrayToAssoc[V interface{}, K comparable, W interface{}](values []V, fc func(v V) (K, W)) map[K]W
func AssocToArray ¶
func AssocToArray[K comparable, V interface{}, W interface{}](values map[K]V, fc func(k K, v V) W) []W
func CmderGetCmd ¶
CmderGetCmd Build a complete query. [WITH xxx] SELECT xxx FROM xxx [INNER JOIN xxx ON xxx] [WHERE xxx] [GROUP BY xxx [HAVING xxx]] [ORDER BY xxx] [LIMIT xxx [OFFSET xxx]]
func CmderGetCount ¶
CmderGetCount Build count query. SELECT COUNT(*) AS count FROM ( [WITH xxx] SELECT xxx FROM xxx [INNER JOIN xxx ON xxx] [WHERE xxx] [GROUP BY xxx [HAVING xxx]] ) AS a SELECT COUNT(*) AS count FROM ( query1 UNION [ALL] query2 [UNION [ALL] ...] ) AS a
func CmderGetOrderLimitOffset ¶
CmderGetOrderLimitOffset Build query table of ORDER BY, LIMIT, OFFSET. [ORDER BY xxx] [LIMIT xxx [OFFSET xxx]]
func CmderGetTable ¶
CmderGetTable Build query table (without ORDER BY, LIMIT, OFFSET). [WITH xxx] SELECT xxx FROM xxx [INNER JOIN xxx ON xxx] [WHERE xxx] [GROUP BY xxx [HAVING xxx]]
func CmderQuery ¶
func CmderQuery(ctx context.Context, way *Way, cmder Cmder, query func(rows *sql.Rows) (err error)) error
CmderQuery execute the built SQL statement and scan query result.
func CmderScanAll ¶
func CmderScanAll(ctx context.Context, way *Way, cmder Cmder, custom func(rows *sql.Rows) error) error
CmderScanAll execute the built SQL statement and scan all from the query results.
func CmderScanOne ¶
CmderScanOne execute the built SQL statement and scan at most once from the query results.
func CmderViewMap ¶
func CmderViewMap(ctx context.Context, way *Way, cmder Cmder) (result []map[string]interface{}, err error)
CmderViewMap execute the built SQL statement and scan all from the query results.
func ColumnInValues ¶
func ColumnInValues[T interface{}](values []T, fc func(tmp T) interface{}) []interface{}
ColumnInValues Build column IN ( values[0].attributeN, values[1].attributeN, values[2].attributeN ... )
func ColumnsInValues ¶
func ColumnsInValues[T interface{}](values []T, fc func(tmp T) []interface{}) [][]interface{}
ColumnsInValues Build ( column1, column2, column3 ... ) IN ( ( values[0].attribute1, values[0].attribute2, values[0].attribute3 ... ), ( values[1].attribute1, values[1].attribute2, values[1].attribute3 ... ) ... )
func GetCountGet ¶
GetCountGet execute the built SQL statement and scan query result, count + get.
func GetCountQuery ¶
func GetCountQuery(get *Get, query func(rows *sql.Rows) (err error), countColumn ...string) (int64, error)
GetCountQuery execute the built SQL statement and scan query result, count + query.
func GetScanAll ¶
GetScanAll execute the built SQL statement and scan all from the query results.
func GetScanOne ¶
GetScanOne execute the built SQL statement and scan at most once from the query results.
func GetViewMap ¶
GetViewMap execute the built SQL statement and scan all from the query results.
func IsEmptyCmder ¶
IsEmptyCmder Check whether the result (SQL statement) of Cmder is empty.
func LastNotEmptyString ¶
LastNotEmptyString get last not empty string, return empty string if it does not exist.
func MergeArray ¶
func MergeArray[V interface{}](values ...[]V) []V
func MergeAssoc ¶
func MergeAssoc[K comparable, V interface{}](values ...map[K]V) map[K]V
func MustAffectedRows ¶
MustAffectedRows at least one row is affected.
func NullDefaultValue ¶
NullDefaultValue Use defaultValue to replace NULL values.
func ParcelCancelPrepare ¶
ParcelCancelPrepare Cancel parcel the SQL statement. ( `subquery` ) => `subquery` OR ( ( `subquery` ) ) => ( `subquery` )
func ParcelPrepare ¶
ParcelPrepare Parcel the SQL statement. `subquery` => ( `subquery` )
func RemoveDuplicate ¶
func RemoveDuplicate(dynamic ...interface{}) (result []interface{})
RemoveDuplicate remove duplicate element.
func RemoveDuplicates ¶
func RemoveDuplicates[T comparable](dynamic ...T) (result []T)
RemoveDuplicates remove duplicate element.
func RowsScanStructAll ¶
func RowsScanStructAll[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, prepare string, args ...interface{}) ([]*V, error)
RowsScanStructAll Rows scan to any struct, based on struct scan data.
func RowsScanStructAllCmder ¶
func RowsScanStructAllCmder[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, cmder Cmder) ([]*V, error)
RowsScanStructAllCmder Rows scan to any struct, based on struct scan data.
func RowsScanStructOne ¶
func RowsScanStructOne[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, prepare string, args ...interface{}) (*V, error)
RowsScanStructOne Rows scan to any struct, based on struct scan data.
func RowsScanStructOneCmder ¶
func RowsScanStructOneCmder[V interface{}](ctx context.Context, way *Way, scan func(rows *sql.Rows, v *V) error, cmder Cmder) (*V, error)
RowsScanStructOneCmder Rows scan to any struct, based on struct scan data.
func ScanSliceStruct ¶
ScanSliceStruct Scan the query result set into the receiving object. Support type *AnyStruct, **AnyStruct, *[]AnyStruct, *[]*AnyStruct, **[]AnyStruct, **[]*AnyStruct ...
func ScanViewMap ¶
ScanViewMap Scan query result to []map[string]interface{}, view query result.
func StructInsert ¶
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 ¶
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 ¶
func StructUpdate(origin interface{}, latest interface{}, tag string, except ...string) (fields []string, values []interface{})
StructUpdate compare origin and latest for update.
Types ¶
type Add ¶
type Add struct {
// contains filtered or unexported fields
}
Add for INSERT.
func (*Add) AddOne ¶
func (s *Add) AddOne(custom func(add AddOneReturnSequenceValue)) (int64, error)
AddOne execute the built SQL statement, return the sequence value of the data.
func (*Add) CmderValues ¶
CmderValues values is a query SQL statement.
func (*Add) ColumnValue ¶
ColumnValue append column-value for insert one or more rows.
func (*Add) ColumnsValues ¶
ColumnsValues set columns and values.
func (*Add) Create ¶
Create value of create should be one of struct{}, *struct{}, map[string]interface{}, []struct, []*struct{}, *[]struct{}, *[]*struct{}.
func (*Add) ExceptPermit ¶
func (s *Add) ExceptPermit(custom func(except UpsertColumns, permit UpsertColumns)) *Add
ExceptPermit Set a list of columns that are not allowed to be inserted and a list of columns that are only allowed to be inserted.
type AddOneReturnSequenceValue ¶
type AddOneReturnSequenceValue interface {
// Adjust You may need to modify the SQL statement to be executed.
Adjust(adjust func(prepare string, args []interface{}) (string, []interface{})) AddOneReturnSequenceValue
// Context Custom context.
Context(ctx context.Context) AddOneReturnSequenceValue
// Execute Customize the method to return the sequence value of inserted data.
Execute(execute func(ctx context.Context, stmt *Stmt, args []interface{}) (sequenceValue int64, err error)) AddOneReturnSequenceValue
// AddOne Insert a record and return the sequence value of the data (usually an auto-incrementing id value).
AddOne() (int64, error)
}
AddOneReturnSequenceValue Insert a record and return the sequence value of the data (usually an auto-incrementing id value).
type Caller ¶
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 Cfg ¶
type Cfg struct {
// DeleteMustUseWhere Deletion of data must be filtered using conditions.
DeleteMustUseWhere bool
// UpdateMustUseWhere Updated data must be filtered using conditions.
UpdateMustUseWhere bool
// Manual For handling different types of databases.
Manual *Manual
// Scan Scan data into structure.
Scan func(rows *sql.Rows, result interface{}, tag string) error
// ScanTag Scan data to tag mapping on structure.
ScanTag string
// TransactionOptions Start transaction.
TransactionOptions *sql.TxOptions
// TransactionMaxDuration Maximum transaction execution time.
TransactionMaxDuration time.Duration
// WarnDuration SQL execution time warning threshold.
WarnDuration time.Duration
// Debugger Debug output SQL script.
Debugger Debugger
// contains filtered or unexported fields
}
Cfg Configure of Way.
type Cmder ¶
type Cmder interface {
// Cmd Get a list of script statements and their corresponding parameters.
Cmd() (prepare string, args []interface{})
}
Cmder Used to build a SQL expression and its corresponding parameter list.
func ConcatCmder ¶
ConcatCmder Concat multiple Cmder.
func ExceptCmder ¶
ExceptCmder CmderA, CmderB ... => ( ( QUERY_A ) EXCEPT ( QUERY_B ) ... )
func IntersectCmder ¶
IntersectCmder CmderA, CmderB ... => ( ( QUERY_A ) INTERSECT ( QUERY_B ) ... )
func ParcelCancelCmder ¶
ParcelCancelCmder Cancel parcel the SQL statement. ( `subquery` ) => `subquery` OR ( ( `subquery` ) ) => ( `subquery` )
func ParcelCmder ¶
ParcelCmder Parcel the SQL statement. `subquery` => ( `subquery` )
func UnionAllCmder ¶
UnionAllCmder CmderA, CmderB, CmderC ... => ( ( QUERY_A ) UNION ALL ( QUERY_B ) UNION ALL ( QUERY_C ) ... )
func UnionCmder ¶
UnionCmder CmderA, CmderB, CmderC ... => ( ( QUERY_A ) UNION ( QUERY_B ) UNION ( QUERY_C ) ... )
type Debugger ¶
type Debugger interface {
// GetLog Get *logger.Logger
GetLog() *logger.Logger
// SetLog Set *logger.Logger
SetLog(log *logger.Logger) Debugger
// SetWay Set *Way
SetWay(way *Way) Debugger
// Debugger Debug output SQL script
Debugger(cmder Cmder) Debugger
}
Debugger Debug output SQL script.
type Del ¶
type Del struct {
// contains filtered or unexported fields
}
Del for DELETE.
func (*Del) TableCmder ¶
func (s *Del) TableCmder(cmder TableCmder) *Del
TableCmder Set table script.
type ErrorNoRowsAffected ¶
type ErrorNoRowsAffected string
ErrorNoRowsAffected Report no affected rows.
func (ErrorNoRowsAffected) Error ¶
func (s ErrorNoRowsAffected) Error() string
type ErrorRecordDoesNotExists ¶
type ErrorRecordDoesNotExists string
ErrorRecordDoesNotExists Report query record does not exist.
func (ErrorRecordDoesNotExists) Error ¶
func (s ErrorRecordDoesNotExists) Error() string
type ErrorTransactionNotStarted ¶
type ErrorTransactionNotStarted string
ErrorTransactionNotStarted Report transaction not started.
func (ErrorTransactionNotStarted) Error ¶
func (s ErrorTransactionNotStarted) Error() string
type Filter ¶
type Filter interface {
Cmder
// Clean Clear the existing conditional filtering of the current object.
Clean() Filter
// Num Number of conditions used.
Num() int
// IsEmpty Is the current object an empty object?
IsEmpty() bool
// Not Negate the result of the current conditional filter object. Multiple negations are allowed.
Not() Filter
// And Use logical operator `AND` to combine custom conditions.
And(prepare string, args ...interface{}) Filter
// Or Use logical operator `OR` to combine custom conditions.
Or(prepare string, args ...interface{}) Filter
// Group Add a new condition group, which is connected by the `AND` logical operator by default.
Group(group func(g Filter)) Filter
// OrGroup Add a new condition group, which is connected by the `OR` logical operator by default.
OrGroup(group func(g Filter)) Filter
// Use Implement import a set of conditional filter objects into the current object.
Use(fs ...Filter) Filter
// New Create a new conditional filter object based on a set of conditional filter objects.
New(fs ...Filter) Filter
// GreaterThan Implement conditional filtering: column > value .
GreaterThan(column string, value interface{}) Filter
// GreaterThanEqual Implement conditional filtering: column >= value .
GreaterThanEqual(column string, value interface{}) Filter
// LessThan Implement conditional filtering: column < value .
LessThan(column string, value interface{}) Filter
// LessThanEqual Implement conditional filtering: column <= value .
LessThanEqual(column string, value interface{}) Filter
// Equal Implement conditional filtering: column = value .
Equal(column string, value interface{}, useNull ...bool) Filter
// Between Implement conditional filtering: column BETWEEN value1 AND value2 .
Between(column string, start interface{}, end interface{}) Filter
// In Implement conditional filtering: column IN ( value1, value2, value3... ) .
In(column string, values ...interface{}) Filter
// InSql Implement conditional filtering: column IN ( subquery ) .
InSql(column string, prepare string, args ...interface{}) Filter
// InCols Implement conditional filtering: ( column1, column2, column3... ) IN ( ( value1, value2, value3... ), ( value21, value22, value23... )... ) .
InCols(columns []string, values ...[]interface{}) Filter
// InColsSql Implement conditional filtering: ( column1, column2, column3... ) IN ( subquery ) .
InColsSql(columns []string, prepare string, args ...interface{}) Filter
// Exists Implement conditional filtering: EXISTS ( subquery ) .
Exists(prepare string, args ...interface{}) Filter
// Like Implement conditional filtering: column LIKE value .
Like(column string, value interface{}) Filter
// IsNull Implement conditional filtering: column IS NULL .
IsNull(column string) Filter
// InQuery Implement conditional filtering: column IN ( subquery ) .
InQuery(column string, subquery Cmder) Filter
// InColsQuery Implement conditional filtering: ( column1, column2, column3... ) IN ( subquery ) .
InColsQuery(columns []string, subquery Cmder) Filter
// ExistsQuery Implement conditional filtering: EXISTS ( subquery ) .
ExistsQuery(subquery Cmder) Filter
// NotEqual Implement conditional filtering: column <> value .
NotEqual(column string, value interface{}, useNotNull ...bool) Filter
// NotBetween Implement conditional filtering: column NOT BETWEEN value1 AND value2 .
NotBetween(column string, start interface{}, end interface{}) Filter
// NotIn Implement conditional filtering: column NOT IN ( value1, value2, value3... ) .
NotIn(column string, values ...interface{}) Filter
// NotInCols Implement conditional filtering: ( column1, column2, column3... ) NOT IN ( ( value1, value2, value3... ), ( value21, value22, value23... )... ) .
NotInCols(columns []string, values ...[]interface{}) Filter
// NotLike Implement conditional filtering: column NOT LIKE value .
NotLike(column string, value interface{}) Filter
// IsNotNull Implement conditional filtering: column IS NOT NULL .
IsNotNull(column string) Filter
// AllQuantifier Implement conditional filtering: column {=||<>||>||>=||<||<=} ALL ( subquery ) .
AllQuantifier(fc func(tmp Quantifier)) Filter
// AnyQuantifier Implement conditional filtering: column {=||<>||>||>=||<||<=} ANY ( subquery ) .
AnyQuantifier(fc func(tmp Quantifier)) Filter
// SomeQuantifier Implement conditional filtering: column {=||<>||>||>=||<||<=} SOME ( subquery ) .
SomeQuantifier(fc func(tmp Quantifier)) Filter
// GetWay For get *Way .
GetWay() *Way
// SetWay For set *Way .
SetWay(way *Way) Filter
// Compare Implement conditional filtering: column1 {=||<>||>||>=||<||<=} column2 .
Compare(column1 string, compare string, column2 string, args ...interface{}) Filter
// CompareEqual Implement conditional filtering: column1 = column2 .
CompareEqual(column1 string, column2 string, args ...interface{}) Filter
// CompareNotEqual Implement conditional filtering: column1 <> column2 .
CompareNotEqual(column1 string, column2 string, args ...interface{}) Filter
// CompareGreaterThan Implement conditional filtering: column1 > column2 .
CompareGreaterThan(column1 string, column2 string, args ...interface{}) Filter
// CompareGreaterThanEqual Implement conditional filtering: column1 >= column2 .
CompareGreaterThanEqual(column1 string, column2 string, args ...interface{}) Filter
// CompareLessThan Implement conditional filtering: column1 < column2 .
CompareLessThan(column1 string, column2 string, args ...interface{}) Filter
// CompareLessThanEqual Implement conditional filtering: column1 <= column2 .
CompareLessThanEqual(column1 string, column2 string, args ...interface{}) Filter
}
Filter Implement SQL statement condition filtering.
func ParcelFilter ¶
ParcelFilter Parcel the SQL filter statement. `SQL_FILTER_STATEMENT` => ( `SQL_FILTER_STATEMENT` )
type Get ¶
type Get struct {
// contains filtered or unexported fields
}
Get for SELECT.
func (*Get) Alias ¶
Alias for table alias name, don't forget to call the current method when the table is a SQL statement.
func (*Get) CountQuery ¶
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 ¶
Order set the column sorting list in batches through regular expressions according to the request parameter value.
func (*Get) ScanOne ¶
ScanOne execute the built SQL statement and scan at most once from the query results.
func (*Get) SetSelect ¶
func (s *Get) SetSelect(queryColumns QueryColumns) *Get
SetSelect Set select object.
type InsertOnConflict ¶
type InsertOnConflict interface {
// OnConflict The column causing the conflict, such as a unique key or primary key, which can be a single column or multiple columns.
OnConflict(onConflicts ...string) InsertOnConflict
// Do The SQL statement that needs to be executed when a data conflict occurs. By default, nothing is done.
Do(prepare string, args ...interface{}) InsertOnConflict
// DoUpdateSet SQL update statements executed when data conflicts occur.
DoUpdateSet(fc func(u InsertOnConflictUpdateSet)) InsertOnConflict
// Cmd The SQL statement and its parameter list that are finally executed.
Cmd() (prepare string, args []interface{})
// InsertOnConflict Executes the SQL statement constructed by the current object.
InsertOnConflict() (int64, error)
}
InsertOnConflict Implement the following SQL statement: INSERT INTO ... ON CONFLICT ( column_a[, column_b, column_c...] ) DO NOTHING /* If a conflict occurs, the insert operation is ignored. */ INSERT INTO ... ON CONFLICT ( column_a[, column_b, column_c...] ) DO UPDATE SET column1 = EXCLUDED.column1, column2 = EXCLUDED.column2, column3 = EXCLUDED.column3, column4 = 'fixed value' ... /* If a conflict occurs, the existing row is updated with the new value */
func NewInsertOnConflict ¶
func NewInsertOnConflict(way *Way, insertPrepare string, insertArgs []interface{}) InsertOnConflict
type InsertOnConflictUpdateSet ¶
type InsertOnConflictUpdateSet interface {
UpdateSet
// Excluded Construct the update expression column1 = EXCLUDED.column1, column2 = EXCLUDED.column2, column3 = EXCLUDED.column3 ...
// This is how the "new" data is accessed that causes the conflict.
Excluded(columns ...string) InsertOnConflictUpdateSet
}
InsertOnConflictUpdateSet Implement the following SQL statement: INSERT INTO ... ON CONFLICT ( column_a[, column_b, column_c...] ) DO UPDATE SET column1 = EXCLUDED.column1, column2 = EXCLUDED.column2, column3 = EXCLUDED.column3, column4 = 'fixed value' ...
func NewInsertOnConflictUpdateSet ¶
func NewInsertOnConflictUpdateSet(way *Way) InsertOnConflictUpdateSet
type InsertValue ¶
type InsertValue interface {
IsEmpty
Cmder
SetSubquery(subquery Cmder) InsertValue
SetValues(values ...[]interface{}) InsertValue
Set(index int, value interface{}) InsertValue
Del(indexes ...int) InsertValue
LenValues() int
GetValues() [][]interface{}
}
InsertValue Constructing insert values.
func NewInsertValue ¶
func NewInsertValue() InsertValue
type JoinCondition ¶
JoinCondition Constructing conditions for join queries.
type Manual ¶
type Manual struct {
// Prepare Adjust the SQL statement format to meet the current database SQL statement format.
Prepare func(prepare string) string
// Replace Helpers for handling different types of databases.
Replace Replace
}
Manual For handling different types of databases.
func Postgresql ¶
func Postgresql() *Manual
type Mod ¶
type Mod struct {
// contains filtered or unexported fields
}
Mod for UPDATE.
func (*Mod) ColumnsValues ¶
ColumnsValues SET column = value by slice, require len(columns) == len(values).
func (*Mod) Compare ¶
Compare For compare old and new to automatically calculate need to update columns.
func (*Mod) ExceptPermit ¶
func (s *Mod) ExceptPermit(custom func(except UpsertColumns, permit UpsertColumns)) *Mod
ExceptPermit Set a list of columns that are not allowed to be updated and a list of columns that are only allowed to be updated.
func (*Mod) GetUpdateSet ¶
GetUpdateSet prepare args of SET.
type Quantifier ¶
type Quantifier interface {
GetQuantifier() string
SetQuantifier(quantifierString string) Quantifier
Equal(column string, subquery Cmder) Quantifier
NotEqual(column string, subquery Cmder) Quantifier
GreaterThan(column string, subquery Cmder) Quantifier
GreaterThanEqual(column string, subquery Cmder) Quantifier
LessThan(column string, subquery Cmder) Quantifier
LessThanEqual(column string, subquery Cmder) Quantifier
}
Quantifier Implement the filter condition: column {=||<>||>||>=||<||<=} [QUANTIFIER ]( subquery ) . QUANTIFIER is usually one of ALL, ANY, SOME ... or EmptyString.
type QueryColumns ¶
type QueryColumns interface {
IsEmpty
Cmder
Index(column string) int
Exists(column string) bool
Add(column string, args ...interface{}) QueryColumns
AddAll(columns ...string) QueryColumns
DelAll(columns ...string) QueryColumns
Len() int
Get() ([]string, map[int][]interface{})
Set(columns []string, columnsArgs map[int][]interface{}) QueryColumns
Use(queryColumns ...QueryColumns) QueryColumns
// Queried Get all columns of the query result.
Queried(excepts ...string) []string
}
QueryColumns Used to build the list of columns to be queried.
func NewQueryColumns ¶
func NewQueryColumns(way *Way) QueryColumns
type QueryGroup ¶
type QueryGroup interface {
IsEmpty
Cmder
Group(columns ...string) QueryGroup
Having(having func(having Filter)) QueryGroup
}
QueryGroup Constructing query groups.
func NewQueryGroup ¶
func NewQueryGroup(way *Way) QueryGroup
type QueryJoin ¶
type QueryJoin interface {
Cmder
GetMaster() TableCmder
SetMaster(master TableCmder) QueryJoin
NewTable(table string, alias string, args ...interface{}) TableCmder
NewSubquery(subquery Cmder, alias string) TableCmder
On(conditions ...func(leftAlias string, rightAlias string) Cmder) JoinCondition
Using(columns ...string) JoinCondition
OnEqual(leftColumn string, rightColumn string, conditions ...func(leftAlias string, rightAlias string) Cmder) JoinCondition
Join(joinTypeString string, leftTable TableCmder, rightTable TableCmder, condition JoinCondition) QueryJoin
InnerJoin(leftTable TableCmder, rightTable TableCmder, condition JoinCondition) QueryJoin
LeftJoin(leftTable TableCmder, rightTable TableCmder, condition JoinCondition) QueryJoin
RightJoin(leftTable TableCmder, rightTable TableCmder, condition JoinCondition) QueryJoin
// Where Don't forget to prefix the specific columns with the table name?
Where(where func(where Filter)) QueryJoin
// Queries Get query columns.
Queries() QueryColumns
}
QueryJoin Constructing multi-table join queries.
func NewQueryJoin ¶
type QueryLimit ¶
type QueryLimit interface {
IsEmpty
Cmder
Limit(limit int64) QueryLimit
Offset(offset int64) QueryLimit
Page(page int64, limit ...int64) QueryLimit
}
QueryLimit Constructing query limits.
func NewQueryLimit ¶
func NewQueryLimit() QueryLimit
type QueryOrder ¶
type QueryOrder interface {
IsEmpty
Cmder
Asc(columns ...string) QueryOrder
Desc(columns ...string) QueryOrder
}
QueryOrder Constructing query orders.
func NewQueryOrder ¶
func NewQueryOrder(way *Way) QueryOrder
type QueryWith ¶
type QueryWith interface {
IsEmpty
Cmder
// Add Set common table expression.
Add(alias string, cmder Cmder) QueryWith
// Del Remove common table expression.
Del(alias string) QueryWith
}
QueryWith CTE: Common Table Expression.
func NewQueryWith ¶
func NewQueryWith() QueryWith
type Reader ¶
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 Replace ¶
type Replace interface {
Get(key string) string
Set(key string, value string) Replace
Del(key string) Replace
Map() map[string]string
Use(mapping map[string]string) Replace
// Gets Batch getting.
Gets(keys []string) []string
// Sets Batch setting.
Sets(mapping map[string]string) Replace
}
Replace For replace identifiers in sql statements. Replace by default, concurrent reads and writes are not safe. If you need concurrent read and write security, you can implement Replace by yourself.
func NewReplace ¶
func NewReplace() Replace
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt Prepare handle.
func (*Stmt) Exec ¶
Exec -> Execute prepared, that can be called repeatedly, return number of rows affected.
func (*Stmt) ExecContext ¶
ExecContext -> Execute prepared, that can be called repeatedly, return number of rows affected.
func (*Stmt) ExecuteContext ¶
ExecuteContext -> Execute prepared, that can be called repeatedly.
func (*Stmt) QueryContext ¶
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 ¶
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 TableCmder ¶
type TableCmder interface {
IsEmpty
Cmder
// Alias Setting aliases for script statements.
Alias(alias string) TableCmder
// GetAlias Getting aliases for script statements.
GetAlias() string
}
TableCmder Used to construct expressions that can use table aliases and their corresponding parameter lists.
func NewCmderGet ¶
func NewCmderGet(alias string, get *Get) TableCmder
func NewTableCmder ¶
func NewTableCmder(prepare string, args []interface{}) TableCmder
type TableColumn ¶
type TableColumn struct {
// contains filtered or unexported fields
}
func NewTableColumn ¶
func NewTableColumn(way *Way, aliases ...string) *TableColumn
func (*TableColumn) AVG ¶
func (s *TableColumn) AVG(column string, aliases ...string) string
AVG COALESCE(AVG(column) ,0)[ AS column_alias_name]
func (*TableColumn) Adjust ¶
func (s *TableColumn) Adjust(adjust func(column string) string, columns ...string) []string
Adjust Batch adjust columns.
func (*TableColumn) Avg ¶
func (s *TableColumn) Avg(column string, aliases ...string) string
Avg AVG(column[, alias])
func (*TableColumn) Column ¶
func (s *TableColumn) Column(column string, aliases ...string) string
Column Add table name prefix to single column name, allowing column alias to be set.
func (*TableColumn) ColumnAll ¶
func (s *TableColumn) ColumnAll(columns ...string) []string
ColumnAll Add table name prefix to column names in batches.
func (*TableColumn) Count ¶
func (s *TableColumn) Count(counts ...string) string
Count Example Count(): COUNT(*) AS `counts` Count("total"): COUNT(*) AS `total` Count("1", "total"): COUNT(1) AS `total` Count("id", "counts"): COUNT(`id`) AS `counts`
func (*TableColumn) MAX ¶
func (s *TableColumn) MAX(column string, aliases ...string) string
MAX COALESCE(MAX(column) ,0)[ AS column_alias_name]
func (*TableColumn) MIN ¶
func (s *TableColumn) MIN(column string, aliases ...string) string
MIN COALESCE(MIN(column) ,0)[ AS column_alias_name]
func (*TableColumn) Max ¶
func (s *TableColumn) Max(column string, aliases ...string) string
Max MAX(column[, alias])
func (*TableColumn) Min ¶
func (s *TableColumn) Min(column string, aliases ...string) string
Min MIN(column[, alias])
func (*TableColumn) SUM ¶
func (s *TableColumn) SUM(column string, aliases ...string) string
SUM COALESCE(SUM(column) ,0)[ AS column_alias_name]
func (*TableColumn) SetAlias ¶
func (s *TableColumn) SetAlias(alias string) *TableColumn
SetAlias Set the alias name value.
type UpdateSet ¶
type UpdateSet interface {
IsEmpty
Cmder
Update(update string, args ...interface{}) UpdateSet
Set(column string, value interface{}) UpdateSet
Decr(column string, decr interface{}) UpdateSet
Incr(column string, incr interface{}) UpdateSet
SetMap(columnValue map[string]interface{}) UpdateSet
SetSlice(columns []string, values []interface{}) UpdateSet
Len() int
GetUpdate() (updates []string, args [][]interface{})
UpdateIndex(prepare string) int
UpdateExists(prepare string) bool
}
UpdateSet Constructing update sets.
func NewUpdateSet ¶
type UpsertColumns ¶
type UpsertColumns interface {
IsEmpty
Cmder
Add(columns ...string) UpsertColumns
Del(columns ...string) UpsertColumns
DelUseIndex(indexes ...int) UpsertColumns
ColumnIndex(column string) int
ColumnExists(column string) bool
Len() int
SetColumns(columns []string) UpsertColumns
GetColumns() []string
GetColumnsMap() map[string]*struct{}
}
UpsertColumns Constructing insert columns.
func NewUpsertColumns ¶
func NewUpsertColumns(way *Way) UpsertColumns
type Way ¶
type Way struct {
// contains filtered or unexported fields
}
Way Quick insert, delete, update, select helper.
func (*Way) BatchUpdate ¶
func (*Way) BatchUpdateContext ¶
func (*Way) CmderExecContext ¶
func (*Way) CmderExecuteContext ¶
func (*Way) CmderQuery ¶
func (*Way) CmderQueryContext ¶
func (*Way) CmderQueryRow ¶
func (*Way) CmderQueryRowContext ¶
func (*Way) CmderTakeAll ¶
func (*Way) CmderTakeAllContext ¶
func (*Way) ExecContext ¶
ExecContext -> Execute the execute sql statement.
func (*Way) ExecuteContext ¶
func (s *Way) ExecuteContext(ctx context.Context, prepare string, args ...interface{}) (sql.Result, error)
ExecuteContext -> Execute the execute sql statement.
func (*Way) GetDatabase ¶
func (*Way) Getter ¶
func (s *Way) Getter(caller Caller, query func(rows *sql.Rows) error, prepare string, args ...interface{}) error
Getter -> Execute the query sql statement with args, no prepared is used.
func (*Way) GetterContext ¶
func (s *Way) GetterContext(ctx context.Context, caller Caller, query func(rows *sql.Rows) error, prepare string, args ...interface{}) (err error)
GetterContext -> Execute the query sql statement with args, no prepared is used.
func (*Way) IsInTransaction ¶
IsInTransaction -> Is the transaction currently in progress?
func (*Way) NewAddOne ¶
func (s *Way) NewAddOne(prepare string, args []interface{}) AddOneReturnSequenceValue
NewAddOne Insert one and get last insert sequence value.
func (*Way) PrepareContext ¶
func (s *Way) PrepareContext(ctx context.Context, prepare string, caller ...Caller) (stmt *Stmt, err error)
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 ¶
QueryRow -> Execute sql statement and return a row data, usually INSERT, UPDATE, DELETE.
func (*Way) QueryRowContext ¶
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) SetterContext ¶
func (s *Way) SetterContext(ctx context.Context, caller Caller, prepare string, args ...interface{}) (int64, error)
SetterContext -> Execute the execute sql statement with args, no prepared is used.
func (*Way) TakeAllContext ¶
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) Transaction ¶
func (s *Way) Transaction(ctx context.Context, fc func(tx *Way) error, opts ...*sql.TxOptions) error
Transaction -> Atomically executes a set of SQL statements. If a transaction has been opened, the opened transaction instance will be used.
func (*Way) TransactionMessage ¶
TransactionMessage -> Set the prompt for the current transaction, can only be set once.
func (*Way) TransactionNew ¶
func (s *Way) TransactionNew(ctx context.Context, fc func(tx *Way) error, opts ...*sql.TxOptions) error
TransactionNew -> Starts a new transaction and executes a set of SQL statements atomically. Does not care whether the current transaction instance is open.
func (*Way) TransactionRetry ¶
func (s *Way) TransactionRetry(ctx context.Context, retries int, fc func(tx *Way) error, opts ...*sql.TxOptions) (err error)
TransactionRetry Starts a new transaction and executes a set of SQL statements atomically. Does not care whether the current transaction instance is open.
func (*Way) WindowFunc ¶
func (s *Way) WindowFunc(alias ...string) *WindowFunc
WindowFunc New a window function object.
type WindowFunc ¶
type WindowFunc struct {
// contains filtered or unexported fields
}
WindowFunc sql window function.
func NewWindowFunc ¶
func NewWindowFunc(way *Way, aliases ...string) *WindowFunc
func (*WindowFunc) Alias ¶
func (s *WindowFunc) Alias(alias string) *WindowFunc
Alias Set the alias of the column that uses the window function.
func (*WindowFunc) Asc ¶
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 ¶
func (s *WindowFunc) Avg(column string) *WindowFunc
Avg AVG() Returns the average of all rows in the window.
func (*WindowFunc) Count ¶
func (s *WindowFunc) Count(column string) *WindowFunc
Count COUNT() Returns the number of rows in the window.
func (*WindowFunc) DenseRank ¶
func (s *WindowFunc) DenseRank() *WindowFunc
DenseRank DENSE_RANK() Similar to RANK(), but does not skip rankings.
func (*WindowFunc) Desc ¶
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 ¶
func (s *WindowFunc) FirstValue(column string) *WindowFunc
FirstValue FIRST_VALUE() Returns the value of the first row in the window.
func (*WindowFunc) Lag ¶
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 ¶
func (s *WindowFunc) LastValue(column string) *WindowFunc
LastValue LAST_VALUE() Returns the value of the last row in the window.
func (*WindowFunc) Lead ¶
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 ¶
func (s *WindowFunc) Max(column string) *WindowFunc
Max MAX() Returns the maximum value within the window.
func (*WindowFunc) Min ¶
func (s *WindowFunc) Min(column string) *WindowFunc
Min MIN() Returns the minimum value within the window.
func (*WindowFunc) NthValue ¶
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 ¶
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 ¶
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 ¶
func (s *WindowFunc) Rank() *WindowFunc
Rank RANK() Assign a rank to each row, if there are duplicate values, the rank is skipped.
func (*WindowFunc) RowNumber ¶
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 ¶
func (s *WindowFunc) Sum(column string) *WindowFunc
Sum SUM() Returns the sum of all rows in the window.
func (*WindowFunc) WindowFrame ¶
func (s *WindowFunc) WindowFrame(windowFrame string) *WindowFunc
WindowFrame Set custom window frame clause.
func (*WindowFunc) WithFunc ¶
func (s *WindowFunc) WithFunc(withFunc string) *WindowFunc
WithFunc Using custom function. for example: CUME_DIST(), PERCENT_RANK(), PERCENTILE_CONT(), PERCENTILE_DISC()...