Merge branch 'main' into lunny/executors
This commit is contained in:
commit
d14289a40e
2
Makefile
2
Makefile
|
|
@ -6,7 +6,7 @@ GOFMT ?= gofmt -s
|
|||
TAGS ?=
|
||||
SED_INPLACE := sed -i
|
||||
|
||||
GO_DIRS := contexts tests core dialects internal log migrate names schemas tags
|
||||
GO_DIRS := contexts tests dialects internal log migrate names schemas tags
|
||||
GOFILES := $(wildcard *.go)
|
||||
GOFILES += $(shell find $(GO_DIRS) -name "*.go" -type f)
|
||||
INTEGRATION_PACKAGES := xorm.io/xorm/v2/tests
|
||||
|
|
|
|||
14
README.md
14
README.md
|
|
@ -105,7 +105,7 @@ engineGroup, err := xorm.NewEngineGroup(masterEngine, []*Engine{slave1Engine, sl
|
|||
|
||||
Then all place where `engine` you can just use `engineGroup`.
|
||||
|
||||
* `Query` runs a SQL string, the returned results is `[]map[string][]byte`, `QueryString` returns `[]map[string]string`, `QueryInterface` returns `[]map[string]interface{}`.
|
||||
* `Query` runs a SQL string, the returned results is `[]map[string][]byte`, `QueryString` returns `[]map[string]string`, `QueryInterface` returns `[]map[string]any`.
|
||||
|
||||
```Go
|
||||
results, err := engine.Query("select * from user")
|
||||
|
|
@ -141,13 +141,13 @@ affected, err := engine.Insert(&user1, &users)
|
|||
// INSERT INTO struct1 () values ()
|
||||
// INSERT INTO struct2 () values (),(),()
|
||||
|
||||
affected, err := engine.Table("user").Insert(map[string]interface{}{
|
||||
affected, err := engine.Table("user").Insert(map[string]any{
|
||||
"name": "lunny",
|
||||
"age": 18,
|
||||
})
|
||||
// INSERT INTO user (name, age) values (?,?)
|
||||
|
||||
affected, err := engine.Table("user").Insert([]map[string]interface{}{
|
||||
affected, err := engine.Table("user").Insert([]map[string]any{
|
||||
{
|
||||
"name": "lunny",
|
||||
"age": 18,
|
||||
|
|
@ -187,7 +187,7 @@ var valuesMap = make(map[string]string)
|
|||
has, err := engine.Table(&user).Where("id = ?", id).Get(&valuesMap)
|
||||
// SELECT * FROM user WHERE id = ?
|
||||
|
||||
var valuesSlice = make([]interface{}, len(cols))
|
||||
var valuesSlice = make([]any, len(cols))
|
||||
has, err := engine.Table(&user).Where("id = ?", id).Cols(cols...).Get(&valuesSlice)
|
||||
// SELECT col1, col2, col3 FROM user WHERE id = ?
|
||||
```
|
||||
|
|
@ -244,13 +244,13 @@ err := engine.Table("user").Select("user.*, detail.*").
|
|||
* `Iterate` and `Rows` query multiple records and record by record handle, there are two methods Iterate and Rows
|
||||
|
||||
```Go
|
||||
err := engine.Iterate(&User{Name:name}, func(idx int, bean interface{}) error {
|
||||
err := engine.Iterate(&User{Name:name}, func(idx int, bean any) error {
|
||||
user := bean.(*User)
|
||||
return nil
|
||||
})
|
||||
// SELECT * FROM user
|
||||
|
||||
err := engine.BufferSize(100).Iterate(&User{Name:name}, func(idx int, bean interface{}) error {
|
||||
err := engine.BufferSize(100).Iterate(&User{Name:name}, func(idx int, bean any) error {
|
||||
user := bean.(*User)
|
||||
return nil
|
||||
})
|
||||
|
|
@ -414,7 +414,7 @@ return session.Commit()
|
|||
* Or you can use `Transaction` to replace above codes.
|
||||
|
||||
```Go
|
||||
res, err := engine.Transaction(func(session *xorm.Session) (interface{}, error) {
|
||||
res, err := engine.Transaction(func(session *xorm.Session) (any, error) {
|
||||
user1 := Userinfo{Username: "xiaoxiao", Departname: "dev", Alias: "lunny", Created: time.Now()}
|
||||
if _, err := session.Insert(&user1); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
14
README_CN.md
14
README_CN.md
|
|
@ -103,7 +103,7 @@ engineGroup, err := xorm.NewEngineGroup(masterEngine, []*Engine{slave1Engine, sl
|
|||
|
||||
所有使用 `engine` 都可以简单的用 `engineGroup` 来替换。
|
||||
|
||||
* `Query` 最原始的也支持SQL语句查询,返回的结果类型为 `[]map[string][]byte`。`QueryString` 返回 `[]map[string]string`, `QueryInterface` 返回 `[]map[string]interface{}`.
|
||||
* `Query` 最原始的也支持SQL语句查询,返回的结果类型为 `[]map[string][]byte`。`QueryString` 返回 `[]map[string]string`, `QueryInterface` 返回 `[]map[string]any`.
|
||||
|
||||
```Go
|
||||
results, err := engine.Query("select * from user")
|
||||
|
|
@ -139,13 +139,13 @@ affected, err := engine.Insert(&user1, &users)
|
|||
// INSERT INTO struct1 () values ()
|
||||
// INSERT INTO struct2 () values (),(),()
|
||||
|
||||
affected, err := engine.Table("user").Insert(map[string]interface{}{
|
||||
affected, err := engine.Table("user").Insert(map[string]any{
|
||||
"name": "lunny",
|
||||
"age": 18,
|
||||
})
|
||||
// INSERT INTO user (name, age) values (?,?)
|
||||
|
||||
affected, err := engine.Table("user").Insert([]map[string]interface{}{
|
||||
affected, err := engine.Table("user").Insert([]map[string]any{
|
||||
{
|
||||
"name": "lunny",
|
||||
"age": 18,
|
||||
|
|
@ -185,7 +185,7 @@ var valuesMap = make(map[string]string)
|
|||
has, err := engine.Table(&user).Where("id = ?", id).Get(&valuesMap)
|
||||
// SELECT * FROM user WHERE id = ?
|
||||
|
||||
var valuesSlice = make([]interface{}, len(cols))
|
||||
var valuesSlice = make([]any, len(cols))
|
||||
has, err := engine.Table(&user).Where("id = ?", id).Cols(cols...).Get(&valuesSlice)
|
||||
// SELECT col1, col2, col3 FROM user WHERE id = ?
|
||||
```
|
||||
|
|
@ -242,13 +242,13 @@ err := engine.Table("user").Select("user.*, detail.*").
|
|||
* `Iterate` 和 `Rows` 根据条件遍历数据库,可以有两种方式: Iterate and Rows
|
||||
|
||||
```Go
|
||||
err := engine.Iterate(&User{Name:name}, func(idx int, bean interface{}) error {
|
||||
err := engine.Iterate(&User{Name:name}, func(idx int, bean any) error {
|
||||
user := bean.(*User)
|
||||
return nil
|
||||
})
|
||||
// SELECT * FROM user
|
||||
|
||||
err := engine.BufferSize(100).Iterate(&User{Name:name}, func(idx int, bean interface{}) error {
|
||||
err := engine.BufferSize(100).Iterate(&User{Name:name}, func(idx int, bean any) error {
|
||||
user := bean.(*User)
|
||||
return nil
|
||||
})
|
||||
|
|
@ -405,7 +405,7 @@ return session.Commit()
|
|||
* 事务的简写方法
|
||||
|
||||
```Go
|
||||
res, err := engine.Transaction(func(session *xorm.Session) (interface{}, error) {
|
||||
res, err := engine.Transaction(func(session *xorm.Session) (any, error) {
|
||||
user1 := Userinfo{Username: "xiaoxiao", Departname: "dev", Alias: "lunny", Created: time.Now()}
|
||||
if _, err := session.Insert(&user1); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
10
columns.go
10
columns.go
|
|
@ -12,7 +12,7 @@ import (
|
|||
"xorm.io/xorm/v2/schemas"
|
||||
)
|
||||
|
||||
func setColumnInt(bean interface{}, col *schemas.Column, t int64) {
|
||||
func setColumnInt(bean any, col *schemas.Column, t int64) {
|
||||
v, err := col.ValueOf(bean)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -27,7 +27,7 @@ func setColumnInt(bean interface{}, col *schemas.Column, t int64) {
|
|||
}
|
||||
}
|
||||
|
||||
func setColumnTime(bean interface{}, col *schemas.Column, t time.Time) {
|
||||
func setColumnTime(bean any, col *schemas.Column, t time.Time) {
|
||||
v, err := col.ValueOf(bean)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -64,19 +64,19 @@ func getFlagForColumn(m map[string]bool, col *schemas.Column) (val bool, has boo
|
|||
}
|
||||
|
||||
// Incr provides a query string like "count = count + 1"
|
||||
func (session *Session) Incr(column string, arg ...interface{}) *Session {
|
||||
func (session *Session) Incr(column string, arg ...any) *Session {
|
||||
session.statement.Incr(column, arg...)
|
||||
return session
|
||||
}
|
||||
|
||||
// Decr provides a query string like "count = count - 1"
|
||||
func (session *Session) Decr(column string, arg ...interface{}) *Session {
|
||||
func (session *Session) Decr(column string, arg ...any) *Session {
|
||||
session.statement.Decr(column, arg...)
|
||||
return session
|
||||
}
|
||||
|
||||
// SetExpr provides a query string like "column = {expression}"
|
||||
func (session *Session) SetExpr(column string, expression interface{}) *Session {
|
||||
func (session *Session) SetExpr(column string, expression any) *Session {
|
||||
session.statement.SetExpr(column, expression)
|
||||
return session
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,43 +8,43 @@ import "xorm.io/builder"
|
|||
|
||||
// SQL provides raw sql input parameter. When you have a complex SQL statement
|
||||
// and cannot use Where, Id, In and etc. Methods to describe, you can use SQL.
|
||||
func (session *Session) SQL(query interface{}, args ...interface{}) *Session {
|
||||
func (session *Session) SQL(query any, args ...any) *Session {
|
||||
session.statement.SQL(query, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// Where provides custom query condition.
|
||||
func (session *Session) Where(query interface{}, args ...interface{}) *Session {
|
||||
func (session *Session) Where(query any, args ...any) *Session {
|
||||
session.statement.Where(query, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// And provides custom query condition.
|
||||
func (session *Session) And(query interface{}, args ...interface{}) *Session {
|
||||
func (session *Session) And(query any, args ...any) *Session {
|
||||
session.statement.And(query, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// Or provides custom query condition.
|
||||
func (session *Session) Or(query interface{}, args ...interface{}) *Session {
|
||||
func (session *Session) Or(query any, args ...any) *Session {
|
||||
session.statement.Or(query, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// ID provides converting id as a query condition
|
||||
func (session *Session) ID(id interface{}) *Session {
|
||||
func (session *Session) ID(id any) *Session {
|
||||
session.statement.ID(id)
|
||||
return session
|
||||
}
|
||||
|
||||
// In provides a query string like "id in (1, 2, 3)"
|
||||
func (session *Session) In(column string, args ...interface{}) *Session {
|
||||
func (session *Session) In(column string, args ...any) *Session {
|
||||
session.statement.In(column, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// NotIn provides a query string like "id in (1, 2, 3)"
|
||||
func (session *Session) NotIn(column string, args ...interface{}) *Session {
|
||||
func (session *Session) NotIn(column string, args ...any) *Session {
|
||||
session.statement.NotIn(column, args...)
|
||||
return session
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,24 +7,24 @@ package contexts
|
|||
// ContextCache is the interface that operates the cache data.
|
||||
type ContextCache interface {
|
||||
// Put puts value into cache with key.
|
||||
Put(key string, val interface{})
|
||||
Put(key string, val any)
|
||||
// Get gets cached value by given key.
|
||||
Get(key string) interface{}
|
||||
Get(key string) any
|
||||
}
|
||||
|
||||
type memoryContextCache map[string]interface{}
|
||||
type memoryContextCache map[string]any
|
||||
|
||||
// NewMemoryContextCache return memoryContextCache
|
||||
func NewMemoryContextCache() memoryContextCache {
|
||||
return make(map[string]interface{})
|
||||
return make(map[string]any)
|
||||
}
|
||||
|
||||
// Put puts value into cache with key.
|
||||
func (m memoryContextCache) Put(key string, val interface{}) {
|
||||
func (m memoryContextCache) Put(key string, val any) {
|
||||
m[key] = val
|
||||
}
|
||||
|
||||
// Get gets cached value by given key.
|
||||
func (m memoryContextCache) Get(key string) interface{} {
|
||||
func (m memoryContextCache) Get(key string) any {
|
||||
return m[key]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@ import (
|
|||
type ContextHook struct {
|
||||
start time.Time
|
||||
Ctx context.Context
|
||||
SQL string // log content or SQL
|
||||
Args []interface{} // if it's a SQL, it's the arguments
|
||||
SQL string // log content or SQL
|
||||
Args []any // if it's a SQL, it's the arguments
|
||||
Result sql.Result
|
||||
ExecuteTime time.Duration
|
||||
Err error // SQL executed error
|
||||
}
|
||||
|
||||
// NewContextHook return context for hook
|
||||
func NewContextHook(ctx context.Context, sql string, args []interface{}) *ContextHook {
|
||||
func NewContextHook(ctx context.Context, sql string, args []any) *ContextHook {
|
||||
return &ContextHook{
|
||||
start: time.Now(),
|
||||
Ctx: ctx,
|
||||
|
|
|
|||
25
delete.go
25
delete.go
|
|
@ -15,17 +15,17 @@ var ErrNeedDeletedCond = errors.New("Delete action needs at least one condition"
|
|||
|
||||
// Delete records, bean's non-empty fields are conditions
|
||||
// At least one condition must be set.
|
||||
func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
||||
func (session *Session) Delete(beans ...any) (int64, error) {
|
||||
return session.delete(beans, true)
|
||||
}
|
||||
|
||||
// Truncate records, bean's non-empty fields are conditions
|
||||
// In contrast to Delete this method allows deletes without conditions.
|
||||
func (session *Session) Truncate(beans ...interface{}) (int64, error) {
|
||||
func (session *Session) Truncate(beans ...any) (int64, error) {
|
||||
return session.delete(beans, false)
|
||||
}
|
||||
|
||||
func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (int64, error) {
|
||||
func (session *Session) delete(beans []any, mustHaveConditions bool) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (in
|
|||
|
||||
var (
|
||||
err error
|
||||
bean interface{}
|
||||
bean any
|
||||
)
|
||||
if len(beans) > 0 {
|
||||
bean = beans[0]
|
||||
|
|
@ -46,7 +46,7 @@ func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (in
|
|||
|
||||
executeBeforeClosures(session, bean)
|
||||
|
||||
if processor, ok := interface{}(bean).(BeforeDeleteProcessor); ok {
|
||||
if processor, ok := any(bean).(BeforeDeleteProcessor); ok {
|
||||
processor.BeforeDelete()
|
||||
}
|
||||
|
||||
|
|
@ -63,13 +63,12 @@ func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (in
|
|||
table := session.statement.RefTable
|
||||
|
||||
realSQLWriter := builder.NewWriter()
|
||||
deleteSQLWriter := builder.NewWriter()
|
||||
if err := session.statement.WriteDelete(realSQLWriter, deleteSQLWriter, session.engine.nowTime); err != nil {
|
||||
if err := session.statement.WriteDelete(realSQLWriter, session.engine.nowTime); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if session.statement.GetUnscoped() || table == nil || table.DeletedColumn() == nil { // tag "deleted" is disabled
|
||||
} else {
|
||||
// if tag "deleted" is enabled, then set the field as deleted value
|
||||
if !session.statement.GetUnscoped() && table != nil && table.DeletedColumn() != nil {
|
||||
deletedColumn := table.DeletedColumn()
|
||||
_, t, err := session.engine.nowTime(deletedColumn)
|
||||
if err != nil {
|
||||
|
|
@ -77,7 +76,7 @@ func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (in
|
|||
}
|
||||
|
||||
colName := deletedColumn.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
session.afterClosures = append(session.afterClosures, func(bean any) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
|
|
@ -95,7 +94,7 @@ func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (in
|
|||
for _, closure := range session.afterClosures {
|
||||
closure(bean)
|
||||
}
|
||||
if processor, ok := interface{}(bean).(AfterDeleteProcessor); ok {
|
||||
if processor, ok := any(bean).(AfterDeleteProcessor); ok {
|
||||
processor.AfterDelete()
|
||||
}
|
||||
} else {
|
||||
|
|
@ -104,12 +103,12 @@ func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (in
|
|||
if value, has := session.afterDeleteBeans[beans[0]]; has && value != nil {
|
||||
*value = append(*value, session.afterClosures...)
|
||||
} else {
|
||||
afterClosures := make([]func(interface{}), lenAfterClosures)
|
||||
afterClosures := make([]func(any), lenAfterClosures)
|
||||
copy(afterClosures, session.afterClosures)
|
||||
session.afterDeleteBeans[bean] = &afterClosures
|
||||
}
|
||||
} else {
|
||||
if _, ok := interface{}(bean).(AfterDeleteProcessor); ok {
|
||||
if _, ok := any(bean).(AfterDeleteProcessor); ok {
|
||||
session.afterDeleteBeans[bean] = nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -749,14 +749,14 @@ func (db *dameng) SetQuotePolicy(quotePolicy QuotePolicy) {
|
|||
}
|
||||
}
|
||||
|
||||
func (db *dameng) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
args := []interface{}{tableName, idxName}
|
||||
func (db *dameng) IndexCheckSQL(tableName, idxName string) (string, []any) {
|
||||
args := []any{tableName, idxName}
|
||||
return `SELECT INDEX_NAME FROM USER_INDEXES ` +
|
||||
`WHERE TABLE_NAME = ? AND INDEX_NAME = ?`, args
|
||||
}
|
||||
|
||||
func (db *dameng) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||
return db.HasRecords(queryer, ctx, `SELECT table_name FROM user_tables WHERE table_name = ?`, tableName)
|
||||
func (db *dameng) IsTableExist(ctx context.Context, queryer core.Queryer, tableName string) (bool, error) {
|
||||
return db.HasRecords(ctx, queryer, `SELECT table_name FROM user_tables WHERE table_name = ?`, tableName)
|
||||
}
|
||||
|
||||
func (db *dameng) IsSequenceExist(ctx context.Context, queryer core.Queryer, seqName string) (bool, error) {
|
||||
|
|
@ -779,11 +779,11 @@ func (db *dameng) IsSequenceExist(ctx context.Context, queryer core.Queryer, seq
|
|||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
func (db *dameng) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
|
||||
args := []interface{}{tableName, colName}
|
||||
func (db *dameng) IsColumnExist(ctx context.Context, queryer core.Queryer, tableName, colName string) (bool, error) {
|
||||
args := []any{tableName, colName}
|
||||
query := "SELECT column_name FROM USER_TAB_COLUMNS WHERE table_name = ?" +
|
||||
" AND column_name = ?"
|
||||
return db.HasRecords(queryer, ctx, query, args...)
|
||||
return db.HasRecords(ctx, queryer, query, args...)
|
||||
}
|
||||
|
||||
var _ sql.Scanner = &dmClobScanner{}
|
||||
|
|
@ -800,7 +800,7 @@ type dmClobObject interface {
|
|||
|
||||
// var _ dmClobObject = &dm.DmClob{}
|
||||
|
||||
func (d *dmClobScanner) Scan(data interface{}) error {
|
||||
func (d *dmClobScanner) Scan(data any) error {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -850,7 +850,7 @@ func addSingleQuote(name string) string {
|
|||
return b.String()
|
||||
}
|
||||
|
||||
func (db *dameng) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
func (db *dameng) GetColumns(ctx context.Context, queryer core.Queryer, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
s := `select column_name from user_cons_columns
|
||||
where constraint_name = (select constraint_name from user_constraints
|
||||
where table_name = ? and constraint_type ='P')`
|
||||
|
|
@ -925,7 +925,7 @@ func (db *dameng) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
}
|
||||
if utils.IndexSlice(pkNames, col.Name) > -1 {
|
||||
col.IsPrimaryKey = true
|
||||
has, err := db.HasRecords(queryer, ctx, "SELECT * FROM USER_SEQUENCES WHERE SEQUENCE_NAME = ?", utils.SeqName(tableName))
|
||||
has, err := db.HasRecords(ctx, queryer, "SELECT * FROM USER_SEQUENCES WHERE SEQUENCE_NAME = ?", utils.SeqName(tableName))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
@ -1002,9 +1002,9 @@ func (db *dameng) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *dameng) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
func (db *dameng) GetTables(ctx context.Context, queryer core.Queryer) ([]*schemas.Table, error) {
|
||||
s := "SELECT table_name FROM user_tables WHERE temporary = 'N' AND table_name NOT LIKE ?"
|
||||
args := []interface{}{strings.ToUpper(db.uri.User), "%$%"}
|
||||
args := []any{strings.ToUpper(db.uri.User), "%$%"}
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
|
|
@ -1028,8 +1028,8 @@ func (db *dameng) GetTables(queryer core.Queryer, ctx context.Context) ([]*schem
|
|||
return tables, nil
|
||||
}
|
||||
|
||||
func (db *dameng) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []interface{}{tableName, tableName}
|
||||
func (db *dameng) GetIndexes(ctx context.Context, queryer core.Queryer, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []any{tableName, tableName}
|
||||
s := "SELECT t.column_name,i.uniqueness,i.index_name FROM user_ind_columns t,user_indexes i " +
|
||||
"WHERE t.index_name = i.index_name and t.table_name = i.table_name and t.table_name =?" +
|
||||
" AND t.index_name not in (SELECT index_name FROM ALL_CONSTRAINTS WHERE CONSTRAINT_TYPE='P' AND table_name = ?)"
|
||||
|
|
@ -1120,7 +1120,7 @@ func (d *damengDriver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (d *damengDriver) GenScanResult(colType string) (interface{}, error) {
|
||||
func (d *damengDriver) GenScanResult(colType string) (any, error) {
|
||||
switch colType {
|
||||
case "CHAR", "NCHAR", "VARCHAR", "VARCHAR2", "NVARCHAR2", "LONG", "CLOB", "NCLOB":
|
||||
var s sql.NullString
|
||||
|
|
@ -1149,13 +1149,13 @@ func (d *damengDriver) GenScanResult(colType string) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (d *damengDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.ColumnType, vv ...interface{}) error {
|
||||
scanResults := make([]interface{}, 0, len(types))
|
||||
func (d *damengDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.ColumnType, vv ...any) error {
|
||||
scanResults := make([]any, 0, len(types))
|
||||
replaces := make([]bool, 0, len(types))
|
||||
var err error
|
||||
for i, v := range vv {
|
||||
var replaced bool
|
||||
var scanResult interface{}
|
||||
var scanResult any
|
||||
switch types[i].DatabaseTypeName() {
|
||||
case "CLOB", "TEXT":
|
||||
scanResult = &dmClobScanner{}
|
||||
|
|
@ -1179,7 +1179,7 @@ func (d *damengDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.Colu
|
|||
if replaced {
|
||||
switch t := scanResults[i].(type) {
|
||||
case *dmClobScanner:
|
||||
var d interface{}
|
||||
var d any
|
||||
if t.valid {
|
||||
d = t.data
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -66,13 +66,13 @@ type Dialect interface {
|
|||
|
||||
AutoIncrStr() string
|
||||
|
||||
GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error)
|
||||
IndexCheckSQL(tableName, idxName string) (string, []interface{})
|
||||
GetIndexes(ctx context.Context, queryer core.Queryer, tableName string) (map[string]*schemas.Index, error)
|
||||
IndexCheckSQL(tableName, idxName string) (string, []any)
|
||||
CreateIndexSQL(tableName string, index *schemas.Index) string
|
||||
DropIndexSQL(tableName string, index *schemas.Index) string
|
||||
|
||||
GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error)
|
||||
IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error)
|
||||
GetTables(ctx context.Context, queryer core.Queryer) ([]*schemas.Table, error)
|
||||
IsTableExist(ctx context.Context, queryer core.Queryer, tableName string) (bool, error)
|
||||
CreateTableSQL(ctx context.Context, queryer core.Queryer, table *schemas.Table, tableName string) (string, bool, error)
|
||||
DropTableSQL(tableName string) (string, bool)
|
||||
|
||||
|
|
@ -80,8 +80,8 @@ type Dialect interface {
|
|||
IsSequenceExist(ctx context.Context, queryer core.Queryer, seqName string) (bool, error)
|
||||
DropSequenceSQL(seqName string) (string, error)
|
||||
|
||||
GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error)
|
||||
IsColumnExist(queryer core.Queryer, ctx context.Context, tableName string, colName string) (bool, error)
|
||||
GetColumns(ctx context.Context, queryer core.Queryer, tableName string) ([]string, map[string]*schemas.Column, error)
|
||||
IsColumnExist(ctx context.Context, queryer core.Queryer, tableName string, colName string) (bool, error)
|
||||
AddColumnSQL(tableName string, col *schemas.Column) string
|
||||
ModifyColumnSQL(tableName string, col *schemas.Column) string
|
||||
|
||||
|
|
@ -177,7 +177,7 @@ func (db *Base) DropTableSQL(tableName string) (string, bool) {
|
|||
}
|
||||
|
||||
// HasRecords returns true if the SQL has records returned
|
||||
func (db *Base) HasRecords(queryer core.Queryer, ctx context.Context, query string, args ...interface{}) (bool, error) {
|
||||
func (db *Base) HasRecords(ctx context.Context, queryer core.Queryer, query string, args ...any) (bool, error) {
|
||||
rows, err := queryer.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
@ -191,7 +191,7 @@ func (db *Base) HasRecords(queryer core.Queryer, ctx context.Context, query stri
|
|||
}
|
||||
|
||||
// IsColumnExist returns true if the column of the table exist
|
||||
func (db *Base) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
|
||||
func (db *Base) IsColumnExist(ctx context.Context, queryer core.Queryer, tableName, colName string) (bool, error) {
|
||||
quote := db.dialect.Quoter().Quote
|
||||
query := fmt.Sprintf(
|
||||
"SELECT %v FROM %v.%v WHERE %v = ? AND %v = ? AND %v = ?",
|
||||
|
|
@ -202,7 +202,7 @@ func (db *Base) IsColumnExist(queryer core.Queryer, ctx context.Context, tableNa
|
|||
quote("TABLE_NAME"),
|
||||
quote("COLUMN_NAME"),
|
||||
)
|
||||
return db.HasRecords(queryer, ctx, query, db.uri.DBName, tableName, colName)
|
||||
return db.HasRecords(ctx, queryer, query, db.uri.DBName, tableName, colName)
|
||||
}
|
||||
|
||||
// AddColumnSQL returns a SQL to add a column
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ type DriverFeatures struct {
|
|||
type Driver interface {
|
||||
Parse(string, string) (*URI, error)
|
||||
Features() *DriverFeatures
|
||||
GenScanResult(string) (interface{}, error) // according given column type generating a suitable scan interface
|
||||
Scan(*ScanContext, *core.Rows, []*sql.ColumnType, ...interface{}) error
|
||||
GenScanResult(string) (any, error) // according given column type generating a suitable scan interface
|
||||
Scan(*ScanContext, *core.Rows, []*sql.ColumnType, ...any) error
|
||||
}
|
||||
|
||||
var drivers = map[string]Driver{}
|
||||
|
|
@ -78,6 +78,6 @@ func OpenDialect(driverName, connstr string) (Dialect, error) {
|
|||
|
||||
type baseDriver struct{}
|
||||
|
||||
func (b *baseDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.ColumnType, v ...interface{}) error {
|
||||
func (b *baseDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.ColumnType, v ...any) error {
|
||||
return rows.Scan(v...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -442,25 +442,25 @@ func (db *mssql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
|||
return fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s", db.quoter.Quote(tableName), s)
|
||||
}
|
||||
|
||||
func (db *mssql) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
args := []interface{}{idxName}
|
||||
func (db *mssql) IndexCheckSQL(tableName, idxName string) (string, []any) {
|
||||
args := []any{idxName}
|
||||
sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?"
|
||||
return sql, args
|
||||
}
|
||||
|
||||
func (db *mssql) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
|
||||
func (db *mssql) IsColumnExist(ctx context.Context, queryer core.Queryer, tableName, colName string) (bool, error) {
|
||||
query := `SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = ? AND "COLUMN_NAME" = ?`
|
||||
|
||||
return db.HasRecords(queryer, ctx, query, tableName, colName)
|
||||
return db.HasRecords(ctx, queryer, query, tableName, colName)
|
||||
}
|
||||
|
||||
func (db *mssql) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||
func (db *mssql) IsTableExist(ctx context.Context, queryer core.Queryer, tableName string) (bool, error) {
|
||||
sql := "select * from sysobjects where id = object_id(N'" + tableName + "') and OBJECTPROPERTY(id, N'IsUserTable') = 1"
|
||||
return db.HasRecords(queryer, ctx, sql)
|
||||
return db.HasRecords(ctx, queryer, sql)
|
||||
}
|
||||
|
||||
func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []interface{}{}
|
||||
func (db *mssql) GetColumns(ctx context.Context, queryer core.Queryer, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []any{}
|
||||
s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
|
||||
"default_is_null" = (CASE WHEN c.text is null THEN 1 ELSE 0 END),
|
||||
replace(replace(isnull(c.text,''),'(',''),')','') as vdefault,
|
||||
|
|
@ -553,8 +553,8 @@ func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *mssql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{}
|
||||
func (db *mssql) GetTables(ctx context.Context, queryer core.Queryer) ([]*schemas.Table, error) {
|
||||
args := []any{}
|
||||
s := `select name from sysobjects where xtype ='U'`
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
|
|
@ -580,8 +580,8 @@ func (db *mssql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schema
|
|||
return tables, nil
|
||||
}
|
||||
|
||||
func (db *mssql) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []interface{}{tableName}
|
||||
func (db *mssql) GetIndexes(ctx context.Context, queryer core.Queryer, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []any{tableName}
|
||||
s := `SELECT
|
||||
IXS.NAME AS [INDEX_NAME],
|
||||
C.NAME AS [COLUMN_NAME],
|
||||
|
|
@ -719,7 +719,7 @@ func (p *odbcDriver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
return &URI{DBName: dbName, DBType: schemas.MSSQL}, nil
|
||||
}
|
||||
|
||||
func (p *odbcDriver) GenScanResult(colType string) (interface{}, error) {
|
||||
func (p *odbcDriver) GenScanResult(colType string) (any, error) {
|
||||
switch colType {
|
||||
case "VARCHAR", "TEXT", "CHAR", "NVARCHAR", "NCHAR", "NTEXT":
|
||||
fallthrough
|
||||
|
|
|
|||
|
|
@ -370,16 +370,16 @@ func (db *mysql) AutoIncrStr() string {
|
|||
return "AUTO_INCREMENT"
|
||||
}
|
||||
|
||||
func (db *mysql) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
args := []interface{}{db.uri.DBName, tableName, idxName}
|
||||
func (db *mysql) IndexCheckSQL(tableName, idxName string) (string, []any) {
|
||||
args := []any{db.uri.DBName, tableName, idxName}
|
||||
sql := "SELECT `INDEX_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS`"
|
||||
sql += " WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? AND `INDEX_NAME`=?"
|
||||
return sql, args
|
||||
}
|
||||
|
||||
func (db *mysql) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||
func (db *mysql) IsTableExist(ctx context.Context, queryer core.Queryer, tableName string) (bool, error) {
|
||||
sql := "SELECT `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? and `TABLE_NAME`=?"
|
||||
return db.HasRecords(queryer, ctx, sql, db.uri.DBName, tableName)
|
||||
return db.HasRecords(ctx, queryer, sql, db.uri.DBName, tableName)
|
||||
}
|
||||
|
||||
func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||
|
|
@ -407,8 +407,8 @@ func (db *mysql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
|||
return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s)
|
||||
}
|
||||
|
||||
func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []interface{}{db.uri.DBName, tableName}
|
||||
func (db *mysql) GetColumns(ctx context.Context, queryer core.Queryer, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []any{db.uri.DBName, tableName}
|
||||
alreadyQuoted := "(INSTR(VERSION(), 'maria') > 0 && " +
|
||||
"(SUBSTRING_INDEX(VERSION(), '.', 1) > 10 || " +
|
||||
"(SUBSTRING_INDEX(VERSION(), '.', 1) = 10 && " +
|
||||
|
|
@ -544,8 +544,8 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
|||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *mysql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{db.uri.DBName}
|
||||
func (db *mysql) GetTables(ctx context.Context, queryer core.Queryer) ([]*schemas.Table, error) {
|
||||
args := []any{db.uri.DBName}
|
||||
s := "SELECT `TABLE_NAME`, `ENGINE`, `AUTO_INCREMENT`, `TABLE_COMMENT`, `TABLE_COLLATION` from " +
|
||||
"`INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB' OR `ENGINE` = 'TokuDB')"
|
||||
|
||||
|
|
@ -596,8 +596,8 @@ func (db *mysql) SetQuotePolicy(quotePolicy QuotePolicy) {
|
|||
}
|
||||
}
|
||||
|
||||
func (db *mysql) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []interface{}{db.uri.DBName, tableName}
|
||||
func (db *mysql) GetIndexes(ctx context.Context, queryer core.Queryer, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []any{db.uri.DBName, tableName}
|
||||
s := "SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? ORDER BY `SEQ_IN_INDEX`"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
|
|
@ -759,7 +759,7 @@ func (p *mysqlDriver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
return uri, nil
|
||||
}
|
||||
|
||||
func (p *mysqlDriver) GenScanResult(colType string) (interface{}, error) {
|
||||
func (p *mysqlDriver) GenScanResult(colType string) (any, error) {
|
||||
colType = strings.Replace(colType, "UNSIGNED ", "", -1)
|
||||
switch colType {
|
||||
case "CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "ENUM", "SET", "JSON":
|
||||
|
|
|
|||
|
|
@ -658,7 +658,7 @@ func (db *oracle) CreateTableSQL(ctx context.Context, queryer core.Queryer, tabl
|
|||
}
|
||||
|
||||
func (db *oracle) IsSequenceExist(ctx context.Context, queryer core.Queryer, seqName string) (bool, error) {
|
||||
return db.HasRecords(queryer, ctx, `SELECT sequence_name FROM user_sequences WHERE sequence_name = :1`, seqName)
|
||||
return db.HasRecords(ctx, queryer, `SELECT sequence_name FROM user_sequences WHERE sequence_name = :1`, seqName)
|
||||
}
|
||||
|
||||
func (db *oracle) SetQuotePolicy(quotePolicy QuotePolicy) {
|
||||
|
|
@ -678,25 +678,25 @@ func (db *oracle) SetQuotePolicy(quotePolicy QuotePolicy) {
|
|||
}
|
||||
}
|
||||
|
||||
func (db *oracle) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
args := []interface{}{tableName, idxName}
|
||||
func (db *oracle) IndexCheckSQL(tableName, idxName string) (string, []any) {
|
||||
args := []any{tableName, idxName}
|
||||
return `SELECT INDEX_NAME FROM USER_INDEXES ` +
|
||||
`WHERE TABLE_NAME = :1 AND INDEX_NAME = :2`, args
|
||||
}
|
||||
|
||||
func (db *oracle) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||
return db.HasRecords(queryer, ctx, `SELECT table_name FROM user_tables WHERE table_name = :1`, tableName)
|
||||
func (db *oracle) IsTableExist(ctx context.Context, queryer core.Queryer, tableName string) (bool, error) {
|
||||
return db.HasRecords(ctx, queryer, `SELECT table_name FROM user_tables WHERE table_name = :1`, tableName)
|
||||
}
|
||||
|
||||
func (db *oracle) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
|
||||
args := []interface{}{tableName, colName}
|
||||
func (db *oracle) IsColumnExist(ctx context.Context, queryer core.Queryer, tableName, colName string) (bool, error) {
|
||||
args := []any{tableName, colName}
|
||||
query := "SELECT column_name FROM USER_TAB_COLUMNS WHERE table_name = :1" +
|
||||
" AND column_name = :2"
|
||||
return db.HasRecords(queryer, ctx, query, args...)
|
||||
return db.HasRecords(ctx, queryer, query, args...)
|
||||
}
|
||||
|
||||
func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []interface{}{tableName}
|
||||
func (db *oracle) GetColumns(ctx context.Context, queryer core.Queryer, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []any{tableName}
|
||||
s := "SELECT column_name,data_default,data_type,data_length,data_precision,data_scale," +
|
||||
"nullable FROM USER_TAB_COLUMNS WHERE table_name = :1"
|
||||
|
||||
|
|
@ -795,8 +795,8 @@ func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *oracle) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{}
|
||||
func (db *oracle) GetTables(ctx context.Context, queryer core.Queryer) ([]*schemas.Table, error) {
|
||||
args := []any{}
|
||||
s := "SELECT table_name FROM user_tables"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
|
|
@ -821,8 +821,8 @@ func (db *oracle) GetTables(queryer core.Queryer, ctx context.Context) ([]*schem
|
|||
return tables, nil
|
||||
}
|
||||
|
||||
func (db *oracle) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []interface{}{tableName}
|
||||
func (db *oracle) GetIndexes(ctx context.Context, queryer core.Queryer, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []any{tableName}
|
||||
s := "SELECT t.column_name,i.uniqueness,i.index_name FROM user_ind_columns t,user_indexes i " +
|
||||
"WHERE t.index_name = i.index_name and t.table_name = i.table_name and t.table_name =:1"
|
||||
|
||||
|
|
@ -911,7 +911,7 @@ func (g *godrorDriver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
func (g *godrorDriver) GenScanResult(colType string) (interface{}, error) {
|
||||
func (g *godrorDriver) GenScanResult(colType string) (any, error) {
|
||||
switch colType {
|
||||
case "CHAR", "NCHAR", "VARCHAR", "VARCHAR2", "NVARCHAR2", "LONG", "CLOB", "NCLOB":
|
||||
var s sql.NullString
|
||||
|
|
|
|||
|
|
@ -998,23 +998,23 @@ func (db *postgres) AutoIncrStr() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (db *postgres) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
func (db *postgres) IndexCheckSQL(tableName, idxName string) (string, []any) {
|
||||
if len(db.getSchema()) == 0 {
|
||||
args := []interface{}{tableName, idxName}
|
||||
args := []any{tableName, idxName}
|
||||
return `SELECT indexname FROM pg_indexes WHERE tablename = ? AND indexname = ?`, args
|
||||
}
|
||||
|
||||
args := []interface{}{db.getSchema(), tableName, idxName}
|
||||
args := []any{db.getSchema(), tableName, idxName}
|
||||
return `SELECT indexname FROM pg_indexes ` +
|
||||
`WHERE schemaname = ? AND tablename = ? AND indexname = ?`, args
|
||||
}
|
||||
|
||||
func (db *postgres) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||
func (db *postgres) IsTableExist(ctx context.Context, queryer core.Queryer, tableName string) (bool, error) {
|
||||
if len(db.getSchema()) == 0 {
|
||||
return db.HasRecords(queryer, ctx, `SELECT tablename FROM pg_tables WHERE tablename = $1`, tableName)
|
||||
return db.HasRecords(ctx, queryer, `SELECT tablename FROM pg_tables WHERE tablename = $1`, tableName)
|
||||
}
|
||||
|
||||
return db.HasRecords(queryer, ctx, `SELECT tablename FROM pg_tables WHERE schemaname = $1 AND tablename = $2`,
|
||||
return db.HasRecords(ctx, queryer, `SELECT tablename FROM pg_tables WHERE schemaname = $1 AND tablename = $2`,
|
||||
db.getSchema(), tableName)
|
||||
}
|
||||
|
||||
|
|
@ -1070,12 +1070,12 @@ func (db *postgres) DropIndexSQL(tableName string, index *schemas.Index) string
|
|||
return fmt.Sprintf("DROP INDEX %v", db.Quoter().Quote(idxName))
|
||||
}
|
||||
|
||||
func (db *postgres) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
|
||||
args := []interface{}{db.getSchema(), tableName, colName}
|
||||
func (db *postgres) IsColumnExist(ctx context.Context, queryer core.Queryer, tableName, colName string) (bool, error) {
|
||||
args := []any{db.getSchema(), tableName, colName}
|
||||
query := "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = $1 AND table_name = $2" +
|
||||
" AND column_name = $3"
|
||||
if len(db.getSchema()) == 0 {
|
||||
args = []interface{}{tableName, colName}
|
||||
args = []any{tableName, colName}
|
||||
query = "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = $1" +
|
||||
" AND column_name = $2"
|
||||
}
|
||||
|
|
@ -1092,8 +1092,8 @@ func (db *postgres) IsColumnExist(queryer core.Queryer, ctx context.Context, tab
|
|||
return false, rows.Err()
|
||||
}
|
||||
|
||||
func (db *postgres) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []interface{}{tableName}
|
||||
func (db *postgres) GetColumns(ctx context.Context, queryer core.Queryer, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []any{tableName}
|
||||
s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, description,
|
||||
CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey,
|
||||
CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey
|
||||
|
|
@ -1245,8 +1245,8 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r' AND c.relname = $1%s AND f.a
|
|||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *postgres) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{}
|
||||
func (db *postgres) GetTables(ctx context.Context, queryer core.Queryer) ([]*schemas.Table, error) {
|
||||
args := []any{}
|
||||
s := "SELECT tablename FROM pg_tables"
|
||||
schema := db.getSchema()
|
||||
if schema != "" {
|
||||
|
|
@ -1288,8 +1288,8 @@ func getIndexColName(indexdef string) []string {
|
|||
return colNames
|
||||
}
|
||||
|
||||
func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []interface{}{tableName}
|
||||
func (db *postgres) GetIndexes(ctx context.Context, queryer core.Queryer, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []any{tableName}
|
||||
s := "SELECT indexname, indexdef FROM pg_indexes WHERE tablename=$1"
|
||||
if len(db.getSchema()) != 0 {
|
||||
args = append(args, db.getSchema())
|
||||
|
|
@ -1522,7 +1522,7 @@ func (p *pqDriver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
func (p *pqDriver) GenScanResult(colType string) (interface{}, error) {
|
||||
func (p *pqDriver) GenScanResult(colType string) (any, error) {
|
||||
switch colType {
|
||||
case "VARCHAR", "TEXT":
|
||||
var s sql.NullString
|
||||
|
|
|
|||
|
|
@ -267,13 +267,13 @@ func (db *sqlite3) AutoIncrStr() string {
|
|||
return "AUTOINCREMENT"
|
||||
}
|
||||
|
||||
func (db *sqlite3) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
|
||||
args := []interface{}{idxName}
|
||||
func (db *sqlite3) IndexCheckSQL(tableName, idxName string) (string, []any) {
|
||||
args := []any{idxName}
|
||||
return "SELECT name FROM sqlite_master WHERE type='index' and name = ?", args
|
||||
}
|
||||
|
||||
func (db *sqlite3) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
|
||||
return db.HasRecords(queryer, ctx, "SELECT name FROM sqlite_master WHERE type='table' and name = ?", tableName)
|
||||
func (db *sqlite3) IsTableExist(ctx context.Context, queryer core.Queryer, tableName string) (bool, error) {
|
||||
return db.HasRecords(ctx, queryer, "SELECT name FROM sqlite_master WHERE type='table' and name = ?", tableName)
|
||||
}
|
||||
|
||||
func (db *sqlite3) DropIndexSQL(tableName string, index *schemas.Index) string {
|
||||
|
|
@ -291,7 +291,7 @@ func (db *sqlite3) DropIndexSQL(tableName string, index *schemas.Index) string {
|
|||
return fmt.Sprintf("DROP INDEX %v", db.Quoter().Quote(idxName))
|
||||
}
|
||||
|
||||
func (db *sqlite3) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
|
||||
func (db *sqlite3) IsColumnExist(ctx context.Context, queryer core.Queryer, tableName, colName string) (bool, error) {
|
||||
query := "SELECT * FROM " + tableName + " LIMIT 0"
|
||||
rows, err := queryer.QueryContext(ctx, query)
|
||||
if err != nil {
|
||||
|
|
@ -375,8 +375,8 @@ func parseString(colStr string) (*schemas.Column, error) {
|
|||
return col, nil
|
||||
}
|
||||
|
||||
func (db *sqlite3) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []interface{}{tableName}
|
||||
func (db *sqlite3) GetColumns(ctx context.Context, queryer core.Queryer, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []any{tableName}
|
||||
s := "SELECT sql FROM sqlite_master WHERE type='table' and name = ?"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
|
|
@ -434,8 +434,8 @@ func (db *sqlite3) GetColumns(queryer core.Queryer, ctx context.Context, tableNa
|
|||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *sqlite3) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{}
|
||||
func (db *sqlite3) GetTables(ctx context.Context, queryer core.Queryer) ([]*schemas.Table, error) {
|
||||
args := []any{}
|
||||
s := "SELECT name FROM sqlite_master WHERE type='table'"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
|
|
@ -462,8 +462,8 @@ func (db *sqlite3) GetTables(queryer core.Queryer, ctx context.Context) ([]*sche
|
|||
return tables, nil
|
||||
}
|
||||
|
||||
func (db *sqlite3) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []interface{}{tableName}
|
||||
func (db *sqlite3) GetIndexes(ctx context.Context, queryer core.Queryer, tableName string) (map[string]*schemas.Index, error) {
|
||||
args := []any{tableName}
|
||||
s := "SELECT sql FROM sqlite_master WHERE type='index' and tbl_name = ?"
|
||||
|
||||
rows, err := queryer.QueryContext(ctx, s, args...)
|
||||
|
|
@ -547,7 +547,7 @@ func (p *sqlite3Driver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
return &URI{DBType: schemas.SQLITE, DBName: dataSourceName}, nil
|
||||
}
|
||||
|
||||
func (p *sqlite3Driver) GenScanResult(colType string) (interface{}, error) {
|
||||
func (p *sqlite3Driver) GenScanResult(colType string) (any, error) {
|
||||
switch colType {
|
||||
case "TEXT":
|
||||
var s sql.NullString
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ func TableNameWithSchema(dialect Dialect, tableName string) string {
|
|||
}
|
||||
|
||||
// TableNameNoSchema returns table name with given tableName
|
||||
func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface{}) string {
|
||||
func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName any) string {
|
||||
quote := dialect.Quoter().Quote
|
||||
switch tt := tableName.(type) {
|
||||
case []string:
|
||||
|
|
@ -37,7 +37,7 @@ func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface
|
|||
} else if len(tt) == 1 {
|
||||
return quote(tt[0])
|
||||
}
|
||||
case []interface{}:
|
||||
case []any:
|
||||
l := len(tt)
|
||||
var table string
|
||||
if l > 0 {
|
||||
|
|
@ -84,7 +84,7 @@ func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface
|
|||
}
|
||||
|
||||
// FullTableName returns table name with quote and schema according parameter
|
||||
func FullTableName(dialect Dialect, mapper names.Mapper, bean interface{}, includeSchema ...bool) string {
|
||||
func FullTableName(dialect Dialect, mapper names.Mapper, bean any, includeSchema ...bool) string {
|
||||
tbName := TableNameNoSchema(dialect, mapper, bean)
|
||||
if len(includeSchema) > 0 && includeSchema[0] && !utils.IsSubQuery(tbName) {
|
||||
tbName = TableNameWithSchema(dialect, tbName)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
// FormatColumnTime format column time
|
||||
func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.Column, t time.Time) (interface{}, error) {
|
||||
func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.Column, t time.Time) (any, error) {
|
||||
if t.IsZero() {
|
||||
if col.Nullable {
|
||||
return nil, nil
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func TestFormatColumnTime(t *testing.T) {
|
|||
location *time.Location
|
||||
column *schemas.Column
|
||||
time time.Time
|
||||
wantRes interface{}
|
||||
wantRes any
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
|
|
|
|||
4
doc.go
4
doc.go
|
|
@ -32,7 +32,7 @@ XORM supports raw SQL execution:
|
|||
|
||||
results, err := engine.QueryString("select * from user")
|
||||
|
||||
3. query with a SQL string, the returned results is []map[string]interface{}
|
||||
3. query with a SQL string, the returned results is []map[string]any
|
||||
|
||||
results, err := engine.QueryInterface("select * from user")
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ There are 8 major ORM methods and many helpful methods to use to operate databas
|
|||
4. Query multiple records and record by record handle, there two methods, one is Iterate,
|
||||
another is Rows
|
||||
|
||||
err := engine.Iterate(new(User), func(i int, bean interface{}) error {
|
||||
err := engine.Iterate(new(User), func(i int, bean any) error {
|
||||
// do something
|
||||
})
|
||||
// SELECT * FROM user
|
||||
|
|
|
|||
98
engine.go
98
engine.go
|
|
@ -149,7 +149,7 @@ func (engine *Engine) Logger() log.ContextLogger {
|
|||
}
|
||||
|
||||
// SetLogger set the new logger
|
||||
func (engine *Engine) SetLogger(logger interface{}) {
|
||||
func (engine *Engine) SetLogger(logger any) {
|
||||
var realLogger log.ContextLogger
|
||||
switch t := logger.(type) {
|
||||
case log.ContextLogger:
|
||||
|
|
@ -285,7 +285,7 @@ func (engine *Engine) Ping() error {
|
|||
// engine.SQL("select * from user").Find(&users)
|
||||
//
|
||||
// This code will execute "select * from user" and set the records to users
|
||||
func (engine *Engine) SQL(query interface{}, args ...interface{}) *Session {
|
||||
func (engine *Engine) SQL(query any, args ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.SQL(query, args...)
|
||||
|
|
@ -308,14 +308,14 @@ func (engine *Engine) NoAutoCondition(no ...bool) *Session {
|
|||
}
|
||||
|
||||
func (engine *Engine) loadTableInfo(ctx context.Context, table *schemas.Table) error {
|
||||
colSeq, cols, err := engine.dialect.GetColumns(engine.db, ctx, table.Name)
|
||||
colSeq, cols, err := engine.dialect.GetColumns(ctx, engine.db, table.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, name := range colSeq {
|
||||
table.AddColumn(cols[name])
|
||||
}
|
||||
indexes, err := engine.dialect.GetIndexes(engine.db, ctx, table.Name)
|
||||
indexes, err := engine.dialect.GetIndexes(ctx, engine.db, table.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -345,7 +345,7 @@ func (engine *Engine) loadTableInfo(ctx context.Context, table *schemas.Table) e
|
|||
|
||||
// DBMetas Retrieve all tables, columns, indexes' informations from database.
|
||||
func (engine *Engine) DBMetas() ([]*schemas.Table, error) {
|
||||
tables, err := engine.dialect.GetTables(engine.db, engine.defaultContext)
|
||||
tables, err := engine.dialect.GetTables(engine.defaultContext, engine.db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -781,28 +781,28 @@ func (engine *Engine) Cascade(trueOrFalse ...bool) *Session {
|
|||
}
|
||||
|
||||
// Where method provide a condition query
|
||||
func (engine *Engine) Where(query interface{}, args ...interface{}) *Session {
|
||||
func (engine *Engine) Where(query any, args ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.Where(query, args...)
|
||||
}
|
||||
|
||||
// ID method provoide a condition as (id) = ?
|
||||
func (engine *Engine) ID(id interface{}) *Session {
|
||||
func (engine *Engine) ID(id any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.ID(id)
|
||||
}
|
||||
|
||||
// Before apply before Processor, affected bean is passed to closure arg
|
||||
func (engine *Engine) Before(closures func(interface{})) *Session {
|
||||
func (engine *Engine) Before(closures func(any)) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.Before(closures)
|
||||
}
|
||||
|
||||
// After apply after insert Processor, affected bean is passed to closure arg
|
||||
func (engine *Engine) After(closures func(interface{})) *Session {
|
||||
func (engine *Engine) After(closures func(any)) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.After(closures)
|
||||
|
|
@ -883,42 +883,42 @@ func (engine *Engine) Nullable(columns ...string) *Session {
|
|||
}
|
||||
|
||||
// In will generate "column IN (?, ?)"
|
||||
func (engine *Engine) In(column string, args ...interface{}) *Session {
|
||||
func (engine *Engine) In(column string, args ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.In(column, args...)
|
||||
}
|
||||
|
||||
// NotIn will generate "column NOT IN (?, ?)"
|
||||
func (engine *Engine) NotIn(column string, args ...interface{}) *Session {
|
||||
func (engine *Engine) NotIn(column string, args ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.NotIn(column, args...)
|
||||
}
|
||||
|
||||
// Incr provides a update string like "column = column + ?"
|
||||
func (engine *Engine) Incr(column string, arg ...interface{}) *Session {
|
||||
func (engine *Engine) Incr(column string, arg ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.Incr(column, arg...)
|
||||
}
|
||||
|
||||
// Decr provides a update string like "column = column - ?"
|
||||
func (engine *Engine) Decr(column string, arg ...interface{}) *Session {
|
||||
func (engine *Engine) Decr(column string, arg ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.Decr(column, arg...)
|
||||
}
|
||||
|
||||
// SetExpr provides a update string like "column = {expression}"
|
||||
func (engine *Engine) SetExpr(column string, expression interface{}) *Session {
|
||||
func (engine *Engine) SetExpr(column string, expression any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.SetExpr(column, expression)
|
||||
}
|
||||
|
||||
// Table temporarily change the Get, Find, Update's table
|
||||
func (engine *Engine) Table(tableNameOrBean interface{}) *Session {
|
||||
func (engine *Engine) Table(tableNameOrBean any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.Table(tableNameOrBean)
|
||||
|
|
@ -957,7 +957,7 @@ func (engine *Engine) Asc(colNames ...string) *Session {
|
|||
}
|
||||
|
||||
// OrderBy will generate "ORDER BY order"
|
||||
func (engine *Engine) OrderBy(order interface{}, args ...interface{}) *Session {
|
||||
func (engine *Engine) OrderBy(order any, args ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.OrderBy(order, args...)
|
||||
|
|
@ -971,7 +971,7 @@ func (engine *Engine) Prepare() *Session {
|
|||
}
|
||||
|
||||
// Join the join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
|
||||
func (engine *Engine) Join(joinOperator string, tablename interface{}, condition interface{}, args ...interface{}) *Session {
|
||||
func (engine *Engine) Join(joinOperator string, tablename any, condition any, args ...any) *Session {
|
||||
session := engine.NewSession()
|
||||
session.isAutoClose = true
|
||||
return session.Join(joinOperator, tablename, condition, args...)
|
||||
|
|
@ -997,39 +997,39 @@ func (engine *Engine) DBVersion() (*schemas.Version, error) {
|
|||
}
|
||||
|
||||
// TableInfo get table info according to bean's content
|
||||
func (engine *Engine) TableInfo(bean interface{}) (*schemas.Table, error) {
|
||||
func (engine *Engine) TableInfo(bean any) (*schemas.Table, error) {
|
||||
v := utils.ReflectValue(bean)
|
||||
return engine.tagParser.ParseWithCache(v)
|
||||
}
|
||||
|
||||
// IsTableEmpty if a table has any reocrd
|
||||
func (engine *Engine) IsTableEmpty(bean interface{}) (bool, error) {
|
||||
func (engine *Engine) IsTableEmpty(bean any) (bool, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.IsTableEmpty(bean)
|
||||
}
|
||||
|
||||
// IsTableExist if a table is exist
|
||||
func (engine *Engine) IsTableExist(beanOrTableName interface{}) (bool, error) {
|
||||
func (engine *Engine) IsTableExist(beanOrTableName any) (bool, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.IsTableExist(beanOrTableName)
|
||||
}
|
||||
|
||||
// TableName returns table name with schema prefix if has
|
||||
func (engine *Engine) TableName(bean interface{}, includeSchema ...bool) string {
|
||||
func (engine *Engine) TableName(bean any, includeSchema ...bool) string {
|
||||
return dialects.FullTableName(engine.dialect, engine.GetTableMapper(), bean, includeSchema...)
|
||||
}
|
||||
|
||||
// CreateIndexes create indexes
|
||||
func (engine *Engine) CreateIndexes(bean interface{}) error {
|
||||
func (engine *Engine) CreateIndexes(bean any) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.CreateIndexes(bean)
|
||||
}
|
||||
|
||||
// CreateUniques create uniques
|
||||
func (engine *Engine) CreateUniques(bean interface{}) error {
|
||||
func (engine *Engine) CreateUniques(bean any) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.CreateUniques(bean)
|
||||
|
|
@ -1041,7 +1041,7 @@ func (engine *Engine) UnMapType(t reflect.Type) {
|
|||
}
|
||||
|
||||
// CreateTables create tabls according bean
|
||||
func (engine *Engine) CreateTables(beans ...interface{}) error {
|
||||
func (engine *Engine) CreateTables(beans ...any) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
|
|
@ -1061,7 +1061,7 @@ func (engine *Engine) CreateTables(beans ...interface{}) error {
|
|||
}
|
||||
|
||||
// DropTables drop specify tables
|
||||
func (engine *Engine) DropTables(beans ...interface{}) error {
|
||||
func (engine *Engine) DropTables(beans ...any) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
|
|
@ -1081,49 +1081,49 @@ func (engine *Engine) DropTables(beans ...interface{}) error {
|
|||
}
|
||||
|
||||
// DropIndexes drop indexes of a table
|
||||
func (engine *Engine) DropIndexes(bean interface{}) error {
|
||||
func (engine *Engine) DropIndexes(bean any) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.DropIndexes(bean)
|
||||
}
|
||||
|
||||
// Exec raw sql
|
||||
func (engine *Engine) Exec(sqlOrArgs ...interface{}) (sql.Result, error) {
|
||||
func (engine *Engine) Exec(sqlOrArgs ...any) (sql.Result, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Exec(sqlOrArgs...)
|
||||
}
|
||||
|
||||
// Query a raw sql and return records as []map[string][]byte
|
||||
func (engine *Engine) Query(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error) {
|
||||
func (engine *Engine) Query(sqlOrArgs ...any) (resultsSlice []map[string][]byte, err error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Query(sqlOrArgs...)
|
||||
}
|
||||
|
||||
// QueryString runs a raw sql and return records as []map[string]string
|
||||
func (engine *Engine) QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error) {
|
||||
func (engine *Engine) QueryString(sqlOrArgs ...any) ([]map[string]string, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.QueryString(sqlOrArgs...)
|
||||
}
|
||||
|
||||
// QueryInterface runs a raw sql and return records as []map[string]interface{}
|
||||
func (engine *Engine) QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error) {
|
||||
// QueryInterface runs a raw sql and return records as []map[string]any
|
||||
func (engine *Engine) QueryInterface(sqlOrArgs ...any) ([]map[string]any, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.QueryInterface(sqlOrArgs...)
|
||||
}
|
||||
|
||||
// Insert one or more records
|
||||
func (engine *Engine) Insert(beans ...interface{}) (int64, error) {
|
||||
func (engine *Engine) Insert(beans ...any) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Insert(beans...)
|
||||
}
|
||||
|
||||
// InsertOne insert only one record
|
||||
func (engine *Engine) InsertOne(bean interface{}) (int64, error) {
|
||||
func (engine *Engine) InsertOne(bean any) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.InsertOne(bean)
|
||||
|
|
@ -1136,7 +1136,7 @@ func (engine *Engine) InsertOne(bean interface{}) (int64, error) {
|
|||
// 1.bool will defaultly be updated content nor conditions
|
||||
// You should call UseBool if you have bool to use.
|
||||
// 2.float32 & float64 may be not inexact as conditions
|
||||
func (engine *Engine) Update(bean interface{}, condiBeans ...interface{}) (int64, error) {
|
||||
func (engine *Engine) Update(bean any, condiBeans ...any) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Update(bean, condiBeans...)
|
||||
|
|
@ -1144,7 +1144,7 @@ func (engine *Engine) Update(bean interface{}, condiBeans ...interface{}) (int64
|
|||
|
||||
// Delete records, bean's non-empty fields are conditions
|
||||
// At least one condition must be set.
|
||||
func (engine *Engine) Delete(beans ...interface{}) (int64, error) {
|
||||
func (engine *Engine) Delete(beans ...any) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Delete(beans...)
|
||||
|
|
@ -1152,7 +1152,7 @@ func (engine *Engine) Delete(beans ...interface{}) (int64, error) {
|
|||
|
||||
// Truncate records, bean's non-empty fields are conditions
|
||||
// In contrast to Delete this method allows deletes without conditions.
|
||||
func (engine *Engine) Truncate(beans ...interface{}) (int64, error) {
|
||||
func (engine *Engine) Truncate(beans ...any) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Truncate(beans...)
|
||||
|
|
@ -1160,14 +1160,14 @@ func (engine *Engine) Truncate(beans ...interface{}) (int64, error) {
|
|||
|
||||
// Get retrieve one record from table, bean's non-empty fields
|
||||
// are conditions
|
||||
func (engine *Engine) Get(beans ...interface{}) (bool, error) {
|
||||
func (engine *Engine) Get(beans ...any) (bool, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Get(beans...)
|
||||
}
|
||||
|
||||
// Exist returns true if the record exist otherwise return false
|
||||
func (engine *Engine) Exist(bean ...interface{}) (bool, error) {
|
||||
func (engine *Engine) Exist(bean ...any) (bool, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Exist(bean...)
|
||||
|
|
@ -1176,14 +1176,14 @@ func (engine *Engine) Exist(bean ...interface{}) (bool, error) {
|
|||
// Find retrieve records from table, condiBeans's non-empty fields
|
||||
// are conditions. beans could be []Struct, []*Struct, map[int64]Struct
|
||||
// map[int64]*Struct
|
||||
func (engine *Engine) Find(beans interface{}, condiBeans ...interface{}) error {
|
||||
func (engine *Engine) Find(beans any, condiBeans ...any) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Find(beans, condiBeans...)
|
||||
}
|
||||
|
||||
// FindAndCount find the results and also return the counts
|
||||
func (engine *Engine) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error) {
|
||||
func (engine *Engine) FindAndCount(rowsSlicePtr any, condiBean ...any) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.FindAndCount(rowsSlicePtr, condiBean...)
|
||||
|
|
@ -1191,7 +1191,7 @@ func (engine *Engine) FindAndCount(rowsSlicePtr interface{}, condiBean ...interf
|
|||
|
||||
// Iterate record by record handle records from table, bean's non-empty fields
|
||||
// are conditions.
|
||||
func (engine *Engine) Iterate(bean interface{}, fun IterFunc) error {
|
||||
func (engine *Engine) Iterate(bean any, fun IterFunc) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Iterate(bean, fun)
|
||||
|
|
@ -1199,41 +1199,41 @@ func (engine *Engine) Iterate(bean interface{}, fun IterFunc) error {
|
|||
|
||||
// Rows return sql.Rows compatible Rows obj, as a forward Iterator object for iterating record by record, bean's non-empty fields
|
||||
// are conditions.
|
||||
func (engine *Engine) Rows(bean interface{}) (*Rows, error) {
|
||||
func (engine *Engine) Rows(bean any) (*Rows, error) {
|
||||
session := engine.NewSession()
|
||||
return session.Rows(bean)
|
||||
}
|
||||
|
||||
// Count counts the records. bean's non-empty fields are conditions.
|
||||
func (engine *Engine) Count(bean ...interface{}) (int64, error) {
|
||||
func (engine *Engine) Count(bean ...any) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Count(bean...)
|
||||
}
|
||||
|
||||
// Sum sum the records by some column. bean's non-empty fields are conditions.
|
||||
func (engine *Engine) Sum(bean interface{}, colName string) (float64, error) {
|
||||
func (engine *Engine) Sum(bean any, colName string) (float64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Sum(bean, colName)
|
||||
}
|
||||
|
||||
// SumInt sum the records by some column. bean's non-empty fields are conditions.
|
||||
func (engine *Engine) SumInt(bean interface{}, colName string) (int64, error) {
|
||||
func (engine *Engine) SumInt(bean any, colName string) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.SumInt(bean, colName)
|
||||
}
|
||||
|
||||
// Sums sum the records by some columns. bean's non-empty fields are conditions.
|
||||
func (engine *Engine) Sums(bean interface{}, colNames ...string) ([]float64, error) {
|
||||
func (engine *Engine) Sums(bean any, colNames ...string) ([]float64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Sums(bean, colNames...)
|
||||
}
|
||||
|
||||
// SumsInt like Sums but return slice of int64 instead of float64.
|
||||
func (engine *Engine) SumsInt(bean interface{}, colNames ...string) ([]int64, error) {
|
||||
func (engine *Engine) SumsInt(bean any, colNames ...string) ([]int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.SumsInt(bean, colNames...)
|
||||
|
|
@ -1254,7 +1254,7 @@ func (engine *Engine) Import(r io.Reader) ([]sql.Result, error) {
|
|||
}
|
||||
|
||||
// nowTime return current time
|
||||
func (engine *Engine) nowTime(col *schemas.Column) (interface{}, time.Time, error) {
|
||||
func (engine *Engine) nowTime(col *schemas.Column) (any, time.Time, error) {
|
||||
t := time.Now()
|
||||
result, err := dialects.FormatColumnTime(engine.dialect, engine.DatabaseTZ, col, t)
|
||||
if err != nil {
|
||||
|
|
@ -1334,7 +1334,7 @@ func (engine *Engine) PingContext(ctx context.Context) error {
|
|||
}
|
||||
|
||||
// Transaction Execute sql wrapped in a transaction(abbr as tx), tx will automatic commit if no errors occurred
|
||||
func (engine *Engine) Transaction(f func(*Session) (interface{}, error)) (interface{}, error) {
|
||||
func (engine *Engine) Transaction(f func(*Session) (any, error)) (any, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ type EngineGroup struct {
|
|||
}
|
||||
|
||||
// NewEngineGroup creates a new engine group
|
||||
func NewEngineGroup(args1 interface{}, args2 interface{}, policies ...GroupPolicy) (*EngineGroup, error) {
|
||||
func NewEngineGroup(args1 any, args2 any, policies ...GroupPolicy) (*EngineGroup, error) {
|
||||
var eg EngineGroup
|
||||
if len(policies) > 0 {
|
||||
eg.policy = policies[0]
|
||||
|
|
@ -128,7 +128,7 @@ func (eg *EngineGroup) SetConnMaxLifetime(d time.Duration) {
|
|||
}
|
||||
|
||||
// SetLogger set the new logger
|
||||
func (eg *EngineGroup) SetLogger(logger interface{}) {
|
||||
func (eg *EngineGroup) SetLogger(logger any) {
|
||||
eg.Engine.SetLogger(logger)
|
||||
for i := 0; i < len(eg.slaves); i++ {
|
||||
eg.slaves[i].SetLogger(logger)
|
||||
|
|
@ -230,28 +230,28 @@ func (eg *EngineGroup) Slaves() []*Engine {
|
|||
}
|
||||
|
||||
// Query execcute a select SQL and return the result
|
||||
func (eg *EngineGroup) Query(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error) {
|
||||
func (eg *EngineGroup) Query(sqlOrArgs ...any) (resultsSlice []map[string][]byte, err error) {
|
||||
sess := eg.NewSession()
|
||||
sess.isAutoClose = true
|
||||
return sess.Query(sqlOrArgs...)
|
||||
}
|
||||
|
||||
// QueryInterface execcute a select SQL and return the result
|
||||
func (eg *EngineGroup) QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error) {
|
||||
func (eg *EngineGroup) QueryInterface(sqlOrArgs ...any) ([]map[string]any, error) {
|
||||
sess := eg.NewSession()
|
||||
sess.isAutoClose = true
|
||||
return sess.QueryInterface(sqlOrArgs...)
|
||||
}
|
||||
|
||||
// QueryString execcute a select SQL and return the result
|
||||
func (eg *EngineGroup) QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error) {
|
||||
func (eg *EngineGroup) QueryString(sqlOrArgs ...any) ([]map[string]string, error) {
|
||||
sess := eg.NewSession()
|
||||
sess.isAutoClose = true
|
||||
return sess.QueryString(sqlOrArgs...)
|
||||
}
|
||||
|
||||
// Rows execcute a select SQL and return the result
|
||||
func (eg *EngineGroup) Rows(bean interface{}) (*Rows, error) {
|
||||
func (eg *EngineGroup) Rows(bean any) (*Rows, error) {
|
||||
sess := eg.NewSession()
|
||||
sess.isAutoClose = true
|
||||
return sess.Rows(bean)
|
||||
|
|
|
|||
8
find.go
8
find.go
|
|
@ -25,7 +25,7 @@ const (
|
|||
// Find retrieve records from table, condiBeans's non-empty fields
|
||||
// are conditions. beans could be []Struct, []*Struct, map[int64]Struct
|
||||
// map[int64]*Struct
|
||||
func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
|
||||
func (session *Session) Find(rowsSlicePtr any, condiBean ...any) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{})
|
|||
}
|
||||
|
||||
// FindAndCount find the results and also return the counts
|
||||
func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error) {
|
||||
func (session *Session) FindAndCount(rowsSlicePtr any, condiBean ...any) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...inte
|
|||
return session.Unscoped().Count()
|
||||
}
|
||||
|
||||
func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
|
||||
func (session *Session) find(rowsSlicePtr any, condiBean ...any) error {
|
||||
defer session.resetStatement()
|
||||
if session.statement.LastError != nil {
|
||||
return session.statement.LastError
|
||||
|
|
@ -208,7 +208,7 @@ func ParseColumnsSchema(fieldNames []string, types []*sql.ColumnType, table *sch
|
|||
return &columnsSchema
|
||||
}
|
||||
|
||||
func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect.Value, sqlStr string, args ...interface{}) error {
|
||||
func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect.Value, sqlStr string, args ...any) error {
|
||||
elemType := containerValue.Type().Elem()
|
||||
var isPointer bool
|
||||
if elemType.Kind() == reflect.Ptr {
|
||||
|
|
|
|||
24
get.go
24
get.go
|
|
@ -23,14 +23,14 @@ var ErrObjectIsNil = errors.New("object should not be nil")
|
|||
|
||||
// Get retrieve one record from database, bean's non-empty fields
|
||||
// will be as conditions
|
||||
func (session *Session) Get(beans ...interface{}) (bool, error) {
|
||||
func (session *Session) Get(beans ...any) (bool, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
return session.get(beans...)
|
||||
}
|
||||
|
||||
func isPtrOfTime(v interface{}) bool {
|
||||
func isPtrOfTime(v any) bool {
|
||||
if _, ok := v.(*time.Time); ok {
|
||||
return true
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ func isPtrOfTime(v interface{}) bool {
|
|||
return el.Type().ConvertibleTo(schemas.TimeType)
|
||||
}
|
||||
|
||||
func (session *Session) get(beans ...interface{}) (bool, error) {
|
||||
func (session *Session) get(beans ...any) (bool, error) {
|
||||
defer session.resetStatement()
|
||||
|
||||
if session.statement.LastError != nil {
|
||||
|
|
@ -70,7 +70,7 @@ func (session *Session) get(beans ...interface{}) (bool, error) {
|
|||
}
|
||||
|
||||
var sqlStr string
|
||||
var args []interface{}
|
||||
var args []any
|
||||
var err error
|
||||
|
||||
if session.statement.RawSQL == "" {
|
||||
|
|
@ -114,7 +114,7 @@ func (session *Session) get(beans ...interface{}) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func isScannableStruct(bean interface{}, typeLen int) bool {
|
||||
func isScannableStruct(bean any, typeLen int) bool {
|
||||
switch bean.(type) {
|
||||
case *time.Time:
|
||||
return false
|
||||
|
|
@ -128,7 +128,7 @@ func isScannableStruct(bean interface{}, typeLen int) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (session *Session) nocacheGet(beanKind reflect.Kind, table *schemas.Table, beans []interface{}, sqlStr string, args ...interface{}) (bool, error) {
|
||||
func (session *Session) nocacheGet(beanKind reflect.Kind, table *schemas.Table, beans []any, sqlStr string, args ...any) (bool, error) {
|
||||
rows, err := session.queryRows(sqlStr, args...)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
@ -159,7 +159,7 @@ func (session *Session) nocacheGet(beanKind reflect.Kind, table *schemas.Table,
|
|||
return true, session.executeProcessors()
|
||||
}
|
||||
|
||||
func (session *Session) scan(rows *core.Rows, table *schemas.Table, firstBeanKind reflect.Kind, beans []interface{}, columnsSchema *ColumnsSchema, types []*sql.ColumnType, fields []string) error {
|
||||
func (session *Session) scan(rows *core.Rows, table *schemas.Table, firstBeanKind reflect.Kind, beans []any, columnsSchema *ColumnsSchema, types []*sql.ColumnType, fields []string) error {
|
||||
if len(beans) == 1 {
|
||||
bean := beans[0]
|
||||
switch firstBeanKind {
|
||||
|
|
@ -189,7 +189,7 @@ func (session *Session) scan(rows *core.Rows, table *schemas.Table, firstBeanKin
|
|||
return session.engine.scan(rows, fields, types, beans...)
|
||||
}
|
||||
|
||||
func (session *Session) getSlice(rows *core.Rows, types []*sql.ColumnType, fields []string, bean interface{}) error {
|
||||
func (session *Session) getSlice(rows *core.Rows, types []*sql.ColumnType, fields []string, bean any) error {
|
||||
switch t := bean.(type) {
|
||||
case *[]string:
|
||||
res, err := session.engine.scanStringInterface(rows, fields, types)
|
||||
|
|
@ -206,7 +206,7 @@ func (session *Session) getSlice(rows *core.Rows, types []*sql.ColumnType, field
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case *[]interface{}:
|
||||
case *[]any:
|
||||
scanResults, err := session.engine.scanInterfaces(rows, fields, types)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -229,7 +229,7 @@ func (session *Session) getSlice(rows *core.Rows, types []*sql.ColumnType, field
|
|||
}
|
||||
}
|
||||
|
||||
func (session *Session) getMap(rows *core.Rows, types []*sql.ColumnType, fields []string, bean interface{}) error {
|
||||
func (session *Session) getMap(rows *core.Rows, types []*sql.ColumnType, fields []string, bean any) error {
|
||||
switch t := bean.(type) {
|
||||
case *map[string]string:
|
||||
scanResults, err := session.engine.scanStringInterface(rows, fields, types)
|
||||
|
|
@ -240,7 +240,7 @@ func (session *Session) getMap(rows *core.Rows, types []*sql.ColumnType, fields
|
|||
(*t)[key] = scanResults[ii].(*sql.NullString).String
|
||||
}
|
||||
return nil
|
||||
case *map[string]interface{}:
|
||||
case *map[string]any:
|
||||
scanResults, err := session.engine.scanInterfaces(rows, fields, types)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -259,7 +259,7 @@ func (session *Session) getMap(rows *core.Rows, types []*sql.ColumnType, fields
|
|||
}
|
||||
|
||||
// Exist returns true if the record exist otherwise return false
|
||||
func (session *Session) Exist(bean ...interface{}) (bool, error) {
|
||||
func (session *Session) Exist(bean ...any) (bool, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
|
|||
64
insert.go
64
insert.go
|
|
@ -23,10 +23,10 @@ import (
|
|||
var ErrNoElementsOnSlice = errors.New("no element on slice when insert")
|
||||
|
||||
// ErrPtrSliceType represents a type error
|
||||
var ErrPtrSliceType = errors.New("A point to a slice is needed")
|
||||
var ErrPtrSliceType = errors.New("a point to a slice is needed")
|
||||
|
||||
// Insert insert one or more beans
|
||||
func (session *Session) Insert(beans ...interface{}) (int64, error) {
|
||||
func (session *Session) Insert(beans ...any) (int64, error) {
|
||||
var affected int64
|
||||
var err error
|
||||
|
||||
|
|
@ -44,9 +44,9 @@ func (session *Session) Insert(beans ...interface{}) (int64, error) {
|
|||
var cnt int64
|
||||
var err error
|
||||
switch v := bean.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
cnt, err = session.insertMapInterface(v)
|
||||
case []map[string]interface{}:
|
||||
case []map[string]any:
|
||||
cnt, err = session.insertMultipleMapInterface(v)
|
||||
case map[string]string:
|
||||
cnt, err = session.insertMapString(v)
|
||||
|
|
@ -69,7 +69,7 @@ func (session *Session) Insert(beans ...interface{}) (int64, error) {
|
|||
return affected, err
|
||||
}
|
||||
|
||||
func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, error) {
|
||||
func (session *Session) insertMultipleStruct(rowsSlicePtr any) (int64, error) {
|
||||
sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr))
|
||||
if sliceValue.Kind() != reflect.Slice {
|
||||
return 0, errors.New("needs a pointer to a slice")
|
||||
|
|
@ -93,7 +93,7 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
|
|||
size = sliceValue.Len()
|
||||
colNames []string
|
||||
colMultiPlaces []string
|
||||
args []interface{}
|
||||
args []any
|
||||
)
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
|
|
@ -114,7 +114,7 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
|
|||
closure(elemValue)
|
||||
}
|
||||
|
||||
if processor, ok := interface{}(elemValue).(BeforeInsertProcessor); ok {
|
||||
if processor, ok := any(elemValue).(BeforeInsertProcessor); ok {
|
||||
processor.BeforeInsert()
|
||||
}
|
||||
// --
|
||||
|
|
@ -161,14 +161,14 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
|
|||
args = append(args, val)
|
||||
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
session.afterClosures = append(session.afterClosures, func(bean any) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
} else if col.IsVersion && session.statement.CheckVersion {
|
||||
args = append(args, 1)
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
session.afterClosures = append(session.afterClosures, func(bean any) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnInt(bean, col, 1)
|
||||
})
|
||||
|
|
@ -218,7 +218,7 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
|
|||
if value, has := session.afterInsertBeans[elemValue]; has && value != nil {
|
||||
*value = append(*value, session.afterClosures...)
|
||||
} else {
|
||||
afterClosures := make([]func(interface{}), lenAfterClosures)
|
||||
afterClosures := make([]func(any), lenAfterClosures)
|
||||
copy(afterClosures, session.afterClosures)
|
||||
session.afterInsertBeans[elemValue] = &afterClosures
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
|
|||
}
|
||||
|
||||
// InsertMulti insert multiple records
|
||||
func (session *Session) InsertMulti(rowsSlicePtr interface{}) (int64, error) {
|
||||
func (session *Session) InsertMulti(rowsSlicePtr any) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -248,7 +248,7 @@ func (session *Session) InsertMulti(rowsSlicePtr interface{}) (int64, error) {
|
|||
return session.insertMultipleStruct(rowsSlicePtr)
|
||||
}
|
||||
|
||||
func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
||||
func (session *Session) insertStruct(bean any) (int64, error) {
|
||||
if err := session.statement.SetRefBean(bean); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -262,7 +262,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
|||
}
|
||||
cleanupProcessorsClosures(&session.beforeClosures) // cleanup after used
|
||||
|
||||
if processor, ok := interface{}(bean).(BeforeInsertProcessor); ok {
|
||||
if processor, ok := any(bean).(BeforeInsertProcessor); ok {
|
||||
processor.BeforeInsert()
|
||||
}
|
||||
|
||||
|
|
@ -280,12 +280,12 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
|||
}
|
||||
sqlStr = session.engine.dialect.Quoter().Replace(sqlStr)
|
||||
|
||||
handleAfterInsertProcessorFunc := func(bean interface{}) {
|
||||
handleAfterInsertProcessorFunc := func(bean any) {
|
||||
if session.isAutoCommit {
|
||||
for _, closure := range session.afterClosures {
|
||||
closure(bean)
|
||||
}
|
||||
if processor, ok := interface{}(bean).(AfterInsertProcessor); ok {
|
||||
if processor, ok := any(bean).(AfterInsertProcessor); ok {
|
||||
processor.AfterInsert()
|
||||
}
|
||||
} else {
|
||||
|
|
@ -294,12 +294,12 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
|||
if value, has := session.afterInsertBeans[bean]; has && value != nil {
|
||||
*value = append(*value, session.afterClosures...)
|
||||
} else {
|
||||
afterClosures := make([]func(interface{}), lenAfterClosures)
|
||||
afterClosures := make([]func(any), lenAfterClosures)
|
||||
copy(afterClosures, session.afterClosures)
|
||||
session.afterInsertBeans[bean] = &afterClosures
|
||||
}
|
||||
} else {
|
||||
if _, ok := interface{}(bean).(AfterInsertProcessor); ok {
|
||||
if _, ok := any(bean).(AfterInsertProcessor); ok {
|
||||
session.afterInsertBeans[bean] = nil
|
||||
}
|
||||
}
|
||||
|
|
@ -310,7 +310,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
|||
// if there is auto increment column and driver don't support return it
|
||||
if len(table.AutoIncrement) > 0 && !session.engine.driver.Features().SupportReturnInsertedID {
|
||||
var sql string
|
||||
var newArgs []interface{}
|
||||
var newArgs []any
|
||||
var needCommit bool
|
||||
var id int64
|
||||
if session.engine.dialect.URI().DBType == schemas.ORACLE || session.engine.dialect.URI().DBType == schemas.DAMENG {
|
||||
|
|
@ -422,7 +422,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
|||
// The in parameter bean must a struct or a point to struct. The return
|
||||
// parameter is inserted and error
|
||||
// Deprecated: Please use Insert directly
|
||||
func (session *Session) InsertOne(bean interface{}) (int64, error) {
|
||||
func (session *Session) InsertOne(bean any) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -431,10 +431,10 @@ func (session *Session) InsertOne(bean interface{}) (int64, error) {
|
|||
}
|
||||
|
||||
// genInsertColumns generates insert needed columns
|
||||
func (session *Session) genInsertColumns(bean interface{}) ([]string, []interface{}, error) {
|
||||
func (session *Session) genInsertColumns(bean any) ([]string, []any, error) {
|
||||
table := session.statement.RefTable
|
||||
colNames := make([]string, 0, len(table.ColumnsSeq()))
|
||||
args := make([]interface{}, 0, len(table.ColumnsSeq()))
|
||||
args := make([]any, 0, len(table.ColumnsSeq()))
|
||||
|
||||
for _, col := range table.Columns() {
|
||||
if col.MapType == schemas.ONLYFROMDB {
|
||||
|
|
@ -491,7 +491,7 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
|||
args = append(args, val)
|
||||
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
session.afterClosures = append(session.afterClosures, func(bean any) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
|
|
@ -510,7 +510,7 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
|||
return colNames, args, nil
|
||||
}
|
||||
|
||||
func (session *Session) insertMapInterface(m map[string]interface{}) (int64, error) {
|
||||
func (session *Session) insertMapInterface(m map[string]any) (int64, error) {
|
||||
if len(m) == 0 {
|
||||
return 0, ErrParamsType
|
||||
}
|
||||
|
|
@ -529,7 +529,7 @@ func (session *Session) insertMapInterface(m map[string]interface{}) (int64, err
|
|||
}
|
||||
sort.Strings(columns)
|
||||
|
||||
args := make([]interface{}, 0, len(m))
|
||||
args := make([]any, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
|
@ -537,7 +537,7 @@ func (session *Session) insertMapInterface(m map[string]interface{}) (int64, err
|
|||
return session.insertMap(columns, args)
|
||||
}
|
||||
|
||||
func (session *Session) insertMultipleMapInterface(maps []map[string]interface{}) (int64, error) {
|
||||
func (session *Session) insertMultipleMapInterface(maps []map[string]any) (int64, error) {
|
||||
if len(maps) == 0 {
|
||||
return 0, ErrNoElementsOnSlice
|
||||
}
|
||||
|
|
@ -556,9 +556,9 @@ func (session *Session) insertMultipleMapInterface(maps []map[string]interface{}
|
|||
}
|
||||
sort.Strings(columns)
|
||||
|
||||
argss := make([][]interface{}, 0, len(maps))
|
||||
argss := make([][]any, 0, len(maps))
|
||||
for _, m := range maps {
|
||||
args := make([]interface{}, 0, len(m))
|
||||
args := make([]any, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
|
@ -588,7 +588,7 @@ func (session *Session) insertMapString(m map[string]string) (int64, error) {
|
|||
|
||||
sort.Strings(columns)
|
||||
|
||||
args := make([]interface{}, 0, len(m))
|
||||
args := make([]any, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
|
@ -615,9 +615,9 @@ func (session *Session) insertMultipleMapString(maps []map[string]string) (int64
|
|||
}
|
||||
sort.Strings(columns)
|
||||
|
||||
argss := make([][]interface{}, 0, len(maps))
|
||||
argss := make([][]any, 0, len(maps))
|
||||
for _, m := range maps {
|
||||
args := make([]interface{}, 0, len(m))
|
||||
args := make([]any, 0, len(m))
|
||||
for _, colName := range columns {
|
||||
args = append(args, m[colName])
|
||||
}
|
||||
|
|
@ -627,7 +627,7 @@ func (session *Session) insertMultipleMapString(maps []map[string]string) (int64
|
|||
return session.insertMultipleMap(columns, argss)
|
||||
}
|
||||
|
||||
func (session *Session) insertMap(columns []string, args []interface{}) (int64, error) {
|
||||
func (session *Session) insertMap(columns []string, args []any) (int64, error) {
|
||||
tableName := session.statement.TableName()
|
||||
if len(tableName) == 0 {
|
||||
return 0, ErrTableNotFound
|
||||
|
|
@ -650,7 +650,7 @@ func (session *Session) insertMap(columns []string, args []interface{}) (int64,
|
|||
return affected, nil
|
||||
}
|
||||
|
||||
func (session *Session) insertMultipleMap(columns []string, argss [][]interface{}) (int64, error) {
|
||||
func (session *Session) insertMultipleMap(columns []string, argss [][]any) (int64, error) {
|
||||
tableName := session.statement.TableName()
|
||||
if len(tableName) == 0 {
|
||||
return 0, ErrTableNotFound
|
||||
|
|
|
|||
90
interface.go
90
interface.go
|
|
@ -24,69 +24,69 @@ type Interface interface {
|
|||
Asc(colNames ...string) *Session
|
||||
BufferSize(size int) *Session
|
||||
Cols(columns ...string) *Session
|
||||
Count(...interface{}) (int64, error)
|
||||
CreateIndexes(bean interface{}) error
|
||||
CreateUniques(bean interface{}) error
|
||||
Decr(column string, arg ...interface{}) *Session
|
||||
Count(...any) (int64, error)
|
||||
CreateIndexes(bean any) error
|
||||
CreateUniques(bean any) error
|
||||
Decr(column string, arg ...any) *Session
|
||||
Desc(...string) *Session
|
||||
Delete(...interface{}) (int64, error)
|
||||
Truncate(...interface{}) (int64, error)
|
||||
Delete(...any) (int64, error)
|
||||
Truncate(...any) (int64, error)
|
||||
Distinct(columns ...string) *Session
|
||||
DropIndexes(bean interface{}) error
|
||||
Exec(sqlOrArgs ...interface{}) (sql.Result, error)
|
||||
Exist(bean ...interface{}) (bool, error)
|
||||
Find(interface{}, ...interface{}) error
|
||||
FindAndCount(interface{}, ...interface{}) (int64, error)
|
||||
Get(...interface{}) (bool, error)
|
||||
DropIndexes(bean any) error
|
||||
Exec(sqlOrArgs ...any) (sql.Result, error)
|
||||
Exist(bean ...any) (bool, error)
|
||||
Find(any, ...any) error
|
||||
FindAndCount(any, ...any) (int64, error)
|
||||
Get(...any) (bool, error)
|
||||
GroupBy(keys string) *Session
|
||||
ID(interface{}) *Session
|
||||
In(string, ...interface{}) *Session
|
||||
Incr(column string, arg ...interface{}) *Session
|
||||
Insert(...interface{}) (int64, error)
|
||||
InsertOne(interface{}) (int64, error)
|
||||
IsTableEmpty(bean interface{}) (bool, error)
|
||||
IsTableExist(beanOrTableName interface{}) (bool, error)
|
||||
Iterate(interface{}, IterFunc) error
|
||||
ID(any) *Session
|
||||
In(string, ...any) *Session
|
||||
Incr(column string, arg ...any) *Session
|
||||
Insert(...any) (int64, error)
|
||||
InsertOne(any) (int64, error)
|
||||
IsTableEmpty(bean any) (bool, error)
|
||||
IsTableExist(beanOrTableName any) (bool, error)
|
||||
Iterate(any, IterFunc) error
|
||||
Limit(int, ...int) *Session
|
||||
MustCols(columns ...string) *Session
|
||||
NoAutoCondition(...bool) *Session
|
||||
NotIn(string, ...interface{}) *Session
|
||||
NotIn(string, ...any) *Session
|
||||
Nullable(...string) *Session
|
||||
Join(joinOperator string, tablename interface{}, condition interface{}, args ...interface{}) *Session
|
||||
Join(joinOperator string, tablename any, condition any, args ...any) *Session
|
||||
Omit(columns ...string) *Session
|
||||
OrderBy(order interface{}, args ...interface{}) *Session
|
||||
OrderBy(order any, args ...any) *Session
|
||||
Ping() error
|
||||
Query(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
|
||||
QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
|
||||
QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error)
|
||||
Rows(bean interface{}) (*Rows, error)
|
||||
SetExpr(string, interface{}) *Session
|
||||
Query(sqlOrArgs ...any) (resultsSlice []map[string][]byte, err error)
|
||||
QueryInterface(sqlOrArgs ...any) ([]map[string]any, error)
|
||||
QueryString(sqlOrArgs ...any) ([]map[string]string, error)
|
||||
Rows(bean any) (*Rows, error)
|
||||
SetExpr(string, any) *Session
|
||||
Select(string) *Session
|
||||
SQL(interface{}, ...interface{}) *Session
|
||||
Sum(bean interface{}, colName string) (float64, error)
|
||||
SumInt(bean interface{}, colName string) (int64, error)
|
||||
Sums(bean interface{}, colNames ...string) ([]float64, error)
|
||||
SumsInt(bean interface{}, colNames ...string) ([]int64, error)
|
||||
Table(tableNameOrBean interface{}) *Session
|
||||
SQL(any, ...any) *Session
|
||||
Sum(bean any, colName string) (float64, error)
|
||||
SumInt(bean any, colName string) (int64, error)
|
||||
Sums(bean any, colNames ...string) ([]float64, error)
|
||||
SumsInt(bean any, colNames ...string) ([]int64, error)
|
||||
Table(tableNameOrBean any) *Session
|
||||
Unscoped() *Session
|
||||
Update(bean interface{}, condiBeans ...interface{}) (int64, error)
|
||||
Update(bean any, condiBeans ...any) (int64, error)
|
||||
UseBool(...string) *Session
|
||||
Where(interface{}, ...interface{}) *Session
|
||||
Where(any, ...any) *Session
|
||||
}
|
||||
|
||||
// EngineInterface defines the interface which Engine, EngineGroup will implementate.
|
||||
type EngineInterface interface {
|
||||
Interface
|
||||
|
||||
Before(func(interface{})) *Session
|
||||
Before(func(any)) *Session
|
||||
Charset(charset string) *Session
|
||||
Context(context.Context) *Session
|
||||
CreateTables(...interface{}) error
|
||||
CreateTables(...any) error
|
||||
DBMetas() ([]*schemas.Table, error)
|
||||
DBVersion() (*schemas.Version, error)
|
||||
Dialect() dialects.Dialect
|
||||
DriverName() string
|
||||
DropTables(...interface{}) error
|
||||
DropTables(...any) error
|
||||
DumpAllToFile(fp string, tp ...schemas.DBType) error
|
||||
GetColumnMapper() names.Mapper
|
||||
GetTableMapper() names.Mapper
|
||||
|
|
@ -100,7 +100,7 @@ type EngineInterface interface {
|
|||
SetConnMaxLifetime(time.Duration)
|
||||
SetColumnMapper(names.Mapper)
|
||||
SetTagIdentifier(string)
|
||||
SetLogger(logger interface{})
|
||||
SetLogger(logger any)
|
||||
SetLogLevel(log.LogLevel)
|
||||
SetMapper(names.Mapper)
|
||||
SetMaxOpenConns(int)
|
||||
|
|
@ -112,12 +112,12 @@ type EngineInterface interface {
|
|||
SetTZLocation(tz *time.Location)
|
||||
AddHook(hook contexts.Hook)
|
||||
ShowSQL(show ...bool)
|
||||
Sync(...interface{}) error
|
||||
Sync2(...interface{}) error
|
||||
SyncWithOptions(SyncOptions, ...interface{}) (*SyncResult, error)
|
||||
Sync(...any) error
|
||||
Sync2(...any) error
|
||||
SyncWithOptions(SyncOptions, ...any) (*SyncResult, error)
|
||||
StoreEngine(storeEngine string) *Session
|
||||
TableInfo(bean interface{}) (*schemas.Table, error)
|
||||
TableName(interface{}, ...bool) string
|
||||
TableInfo(bean any) (*schemas.Table, error)
|
||||
TableName(any, ...bool) string
|
||||
UnMapType(reflect.Type)
|
||||
EnableSessionID(bool)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
// AsBool convert interface as bool
|
||||
func AsBool(src interface{}) (bool, error) {
|
||||
func AsBool(src any) (bool, error) {
|
||||
switch v := src.(type) {
|
||||
case bool:
|
||||
return v, nil
|
||||
|
|
|
|||
|
|
@ -55,10 +55,10 @@ func cloneBytes(b []byte) []byte {
|
|||
// Assign copies to dest the value in src, converting it if possible.
|
||||
// An error is returned if the copy would result in loss of information.
|
||||
// dest should be a pointer type.
|
||||
func Assign(dest, src interface{}, originalLocation *time.Location, convertedLocation *time.Location) error {
|
||||
func Assign(dest, src any, originalLocation *time.Location, convertedLocation *time.Location) error {
|
||||
// Common cases, without reflect.
|
||||
switch s := src.(type) {
|
||||
case *interface{}:
|
||||
case *any:
|
||||
return Assign(dest, *s, originalLocation, convertedLocation)
|
||||
case string:
|
||||
switch d := dest.(type) {
|
||||
|
|
@ -83,7 +83,7 @@ func Assign(dest, src interface{}, originalLocation *time.Location, convertedLoc
|
|||
}
|
||||
*d = string(s)
|
||||
return nil
|
||||
case *interface{}:
|
||||
case *any:
|
||||
if d == nil {
|
||||
return ErrNilPtr
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ func Assign(dest, src interface{}, originalLocation *time.Location, convertedLoc
|
|||
}
|
||||
case nil:
|
||||
switch d := dest.(type) {
|
||||
case *interface{}:
|
||||
case *any:
|
||||
if d == nil {
|
||||
return ErrNilPtr
|
||||
}
|
||||
|
|
@ -295,7 +295,7 @@ func Assign(dest, src interface{}, originalLocation *time.Location, convertedLoc
|
|||
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
var sv = reflect.ValueOf(src)
|
||||
sv := reflect.ValueOf(src)
|
||||
switch sv.Kind() {
|
||||
case reflect.Bool,
|
||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
|
|
@ -315,7 +315,7 @@ func Assign(dest, src interface{}, originalLocation *time.Location, convertedLoc
|
|||
*d = bv.(bool)
|
||||
}
|
||||
return err
|
||||
case *interface{}:
|
||||
case *any:
|
||||
*d = src
|
||||
return nil
|
||||
}
|
||||
|
|
@ -329,11 +329,11 @@ var (
|
|||
)
|
||||
|
||||
// AssignValue assign src as dv
|
||||
func AssignValue(dv reflect.Value, src interface{}) error {
|
||||
func AssignValue(dv reflect.Value, src any) error {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
if v, ok := src.(*interface{}); ok {
|
||||
if v, ok := src.(*any); ok {
|
||||
return AssignValue(dv, *v)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
// AsFloat64 convets interface as float64
|
||||
func AsFloat64(src interface{}) (float64, error) {
|
||||
func AsFloat64(src any) (float64, error) {
|
||||
switch v := src.(type) {
|
||||
case int:
|
||||
return float64(v), nil
|
||||
|
|
@ -64,7 +64,7 @@ func AsFloat64(src interface{}) (float64, error) {
|
|||
}
|
||||
|
||||
// AsBigFloat converts interface as big.Float
|
||||
func AsBigFloat(src interface{}) (*big.Float, error) {
|
||||
func AsBigFloat(src any) (*big.Float, error) {
|
||||
res := big.NewFloat(0)
|
||||
switch v := src.(type) {
|
||||
case int:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
// AsInt64 converts interface as int64
|
||||
func AsInt64(src interface{}) (int64, error) {
|
||||
func AsInt64(src any) (int64, error) {
|
||||
switch v := src.(type) {
|
||||
case int:
|
||||
return int64(v), nil
|
||||
|
|
@ -112,7 +112,7 @@ func AsInt64(src interface{}) (int64, error) {
|
|||
}
|
||||
|
||||
// AsUint64 converts interface as uint64
|
||||
func AsUint64(src interface{}) (uint64, error) {
|
||||
func AsUint64(src any) (uint64, error) {
|
||||
switch v := src.(type) {
|
||||
case int:
|
||||
return uint64(v), nil
|
||||
|
|
@ -171,7 +171,7 @@ type NullUint64 struct {
|
|||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (n *NullUint64) Scan(value interface{}) error {
|
||||
func (n *NullUint64) Scan(value any) error {
|
||||
if value == nil {
|
||||
n.Uint64, n.Valid = 0, false
|
||||
return nil
|
||||
|
|
@ -201,7 +201,7 @@ type NullUint32 struct {
|
|||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (n *NullUint32) Scan(value interface{}) error {
|
||||
func (n *NullUint32) Scan(value any) error {
|
||||
if value == nil {
|
||||
n.Uint32, n.Valid = 0, false
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
// Interface2Interface converts interface of pointer as interface of value
|
||||
func Interface2Interface(userLocation *time.Location, v interface{}) (interface{}, error) {
|
||||
func Interface2Interface(userLocation *time.Location, v any) (any, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
func AsKind(vv reflect.Value, tp reflect.Type) (interface{}, error) {
|
||||
func AsKind(vv reflect.Value, tp reflect.Type) (any, error) {
|
||||
switch tp.Kind() {
|
||||
case reflect.Ptr:
|
||||
return AsKind(vv.Elem(), tp.Elem())
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@ package convert
|
|||
|
||||
import "database/sql"
|
||||
|
||||
var (
|
||||
_ sql.Scanner = &EmptyScanner{}
|
||||
)
|
||||
var _ sql.Scanner = &EmptyScanner{}
|
||||
|
||||
// EmptyScanner represents an empty scanner which will ignore the scan
|
||||
type EmptyScanner struct{}
|
||||
|
||||
// Scan implements sql.Scanner
|
||||
func (EmptyScanner) Scan(value interface{}) error {
|
||||
func (EmptyScanner) Scan(value any) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
// AsString converts interface as string
|
||||
func AsString(src interface{}) string {
|
||||
func AsString(src any) string {
|
||||
switch v := src.(type) {
|
||||
case string:
|
||||
return v
|
||||
|
|
@ -42,7 +42,7 @@ func AsString(src interface{}) string {
|
|||
}
|
||||
|
||||
// AsBytes converts interface as bytes
|
||||
func AsBytes(src interface{}) ([]byte, bool) {
|
||||
func AsBytes(src any) ([]byte, bool) {
|
||||
switch t := src.(type) {
|
||||
case []byte:
|
||||
return t, true
|
||||
|
|
|
|||
|
|
@ -68,17 +68,13 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
|||
dt = dt.In(convertedLocation)
|
||||
return &dt, nil
|
||||
} else if len(s) == 8 && s[2] == ':' && s[5] == ':' {
|
||||
currentDate := time.Now()
|
||||
dt, err := time.ParseInLocation("15:04:05", s, originalLocation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// add current date for correct time locations
|
||||
dt = dt.AddDate(currentDate.Year(), int(currentDate.Month()), currentDate.Day())
|
||||
dt = dt.In(convertedLocation)
|
||||
// back to zero year
|
||||
dt = dt.AddDate(-currentDate.Year(), int(-currentDate.Month()), -currentDate.Day())
|
||||
return &dt, nil
|
||||
res := time.Date(0, time.January, 1, dt.Hour(), dt.Minute(), dt.Second(), 0, convertedLocation)
|
||||
return &res, nil
|
||||
} else {
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err == nil {
|
||||
|
|
@ -90,7 +86,7 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
|
|||
}
|
||||
|
||||
// AsTime converts interface as time
|
||||
func AsTime(src interface{}, dbLoc *time.Location, uiLoc *time.Location) (*time.Time, error) {
|
||||
func AsTime(src any, dbLoc *time.Location, uiLoc *time.Location) (*time.Time, error) {
|
||||
switch t := src.(type) {
|
||||
case string:
|
||||
return String2Time(t, dbLoc, uiLoc)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func TestString2Time(t *testing.T) {
|
||||
expectedLoc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
expectedLoc := time.FixedZone("CST", 8*3600)
|
||||
|
||||
cases := map[string]time.Time{
|
||||
"2021-08-10": time.Date(2021, 8, 10, 8, 0, 0, 0, expectedLoc),
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ import (
|
|||
var DefaultCacheSize = 200
|
||||
|
||||
// MapToSlice map query and struct as sql and args
|
||||
func MapToSlice(query string, mp interface{}) (string, []interface{}, error) {
|
||||
func MapToSlice(query string, mp any) (string, []any, error) {
|
||||
vv := reflect.ValueOf(mp)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
|
||||
return "", []interface{}{}, ErrNoMapPointer
|
||||
return "", []any{}, ErrNoMapPointer
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0, len(vv.Elem().MapKeys()))
|
||||
args := make([]any, 0, len(vv.Elem().MapKeys()))
|
||||
var err error
|
||||
query = re.ReplaceAllStringFunc(query, func(src string) string {
|
||||
v := vv.Elem().MapIndex(reflect.ValueOf(src[1:]))
|
||||
|
|
@ -44,13 +44,13 @@ func MapToSlice(query string, mp interface{}) (string, []interface{}, error) {
|
|||
}
|
||||
|
||||
// StructToSlice converts a query and struct as sql and args
|
||||
func StructToSlice(query string, st interface{}) (string, []interface{}, error) {
|
||||
func StructToSlice(query string, st any) (string, []any, error) {
|
||||
vv := reflect.ValueOf(st)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
|
||||
return "", []interface{}{}, ErrNoStructPointer
|
||||
return "", []any{}, ErrNoStructPointer
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0)
|
||||
args := make([]any, 0)
|
||||
var err error
|
||||
query = re.ReplaceAllStringFunc(query, func(src string) string {
|
||||
fv := vv.Elem().FieldByName(src[1:]).Interface()
|
||||
|
|
@ -67,7 +67,7 @@ func StructToSlice(query string, st interface{}) (string, []interface{}, error)
|
|||
return "?"
|
||||
})
|
||||
if err != nil {
|
||||
return "", []interface{}{}, err
|
||||
return "", []any{}, err
|
||||
}
|
||||
return query, args, nil
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ func (db *DB) reflectNew(typ reflect.Type) reflect.Value {
|
|||
}
|
||||
|
||||
// QueryContext overwrites sql.DB.QueryContext
|
||||
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
|
||||
func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error) {
|
||||
hookCtx := contexts.NewContextHook(ctx, query, args)
|
||||
ctx, err := db.beforeProcess(hookCtx)
|
||||
if err != nil {
|
||||
|
|
@ -156,12 +156,12 @@ func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{
|
|||
}
|
||||
|
||||
// Query overwrites sql.DB.Query
|
||||
func (db *DB) Query(query string, args ...interface{}) (*Rows, error) {
|
||||
func (db *DB) Query(query string, args ...any) (*Rows, error) {
|
||||
return db.QueryContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
// QueryMapContext executes query with parameters via map and context
|
||||
func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error) {
|
||||
func (db *DB) QueryMapContext(ctx context.Context, query string, mp any) (*Rows, error) {
|
||||
query, args, err := MapToSlice(query, mp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -170,12 +170,12 @@ func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{})
|
|||
}
|
||||
|
||||
// QueryMap executes query with parameters via map
|
||||
func (db *DB) QueryMap(query string, mp interface{}) (*Rows, error) {
|
||||
func (db *DB) QueryMap(query string, mp any) (*Rows, error) {
|
||||
return db.QueryMapContext(context.Background(), query, mp)
|
||||
}
|
||||
|
||||
// QueryStructContext query rows with struct
|
||||
func (db *DB) QueryStructContext(ctx context.Context, query string, st interface{}) (*Rows, error) {
|
||||
func (db *DB) QueryStructContext(ctx context.Context, query string, st any) (*Rows, error) {
|
||||
query, args, err := StructToSlice(query, st)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -184,12 +184,12 @@ func (db *DB) QueryStructContext(ctx context.Context, query string, st interface
|
|||
}
|
||||
|
||||
// QueryStruct query rows with struct
|
||||
func (db *DB) QueryStruct(query string, st interface{}) (*Rows, error) {
|
||||
func (db *DB) QueryStruct(query string, st any) (*Rows, error) {
|
||||
return db.QueryStructContext(context.Background(), query, st)
|
||||
}
|
||||
|
||||
// QueryRowContext query row with args
|
||||
func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row {
|
||||
func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *Row {
|
||||
rows, err := db.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return &Row{nil, err}
|
||||
|
|
@ -198,12 +198,12 @@ func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interfa
|
|||
}
|
||||
|
||||
// QueryRow query row with args
|
||||
func (db *DB) QueryRow(query string, args ...interface{}) *Row {
|
||||
func (db *DB) QueryRow(query string, args ...any) *Row {
|
||||
return db.QueryRowContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
// QueryRowMapContext query row with map
|
||||
func (db *DB) QueryRowMapContext(ctx context.Context, query string, mp interface{}) *Row {
|
||||
func (db *DB) QueryRowMapContext(ctx context.Context, query string, mp any) *Row {
|
||||
query, args, err := MapToSlice(query, mp)
|
||||
if err != nil {
|
||||
return &Row{nil, err}
|
||||
|
|
@ -212,12 +212,12 @@ func (db *DB) QueryRowMapContext(ctx context.Context, query string, mp interface
|
|||
}
|
||||
|
||||
// QueryRowMap query row with map
|
||||
func (db *DB) QueryRowMap(query string, mp interface{}) *Row {
|
||||
func (db *DB) QueryRowMap(query string, mp any) *Row {
|
||||
return db.QueryRowMapContext(context.Background(), query, mp)
|
||||
}
|
||||
|
||||
// QueryRowStructContext query row with struct
|
||||
func (db *DB) QueryRowStructContext(ctx context.Context, query string, st interface{}) *Row {
|
||||
func (db *DB) QueryRowStructContext(ctx context.Context, query string, st any) *Row {
|
||||
query, args, err := StructToSlice(query, st)
|
||||
if err != nil {
|
||||
return &Row{nil, err}
|
||||
|
|
@ -226,7 +226,7 @@ func (db *DB) QueryRowStructContext(ctx context.Context, query string, st interf
|
|||
}
|
||||
|
||||
// QueryRowStruct query row with struct
|
||||
func (db *DB) QueryRowStruct(query string, st interface{}) *Row {
|
||||
func (db *DB) QueryRowStruct(query string, st any) *Row {
|
||||
return db.QueryRowStructContext(context.Background(), query, st)
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +235,7 @@ var re = regexp.MustCompile(`[?](\w+)`)
|
|||
// ExecMapContext exec map with context.ContextHook
|
||||
// insert into (name) values (?)
|
||||
// insert into (name) values (?name)
|
||||
func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error) {
|
||||
func (db *DB) ExecMapContext(ctx context.Context, query string, mp any) (sql.Result, error) {
|
||||
query, args, err := MapToSlice(query, mp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -244,12 +244,12 @@ func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{})
|
|||
}
|
||||
|
||||
// ExecMap exec query with map
|
||||
func (db *DB) ExecMap(query string, mp interface{}) (sql.Result, error) {
|
||||
func (db *DB) ExecMap(query string, mp any) (sql.Result, error) {
|
||||
return db.ExecMapContext(context.Background(), query, mp)
|
||||
}
|
||||
|
||||
// ExecStructContext exec query with map
|
||||
func (db *DB) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error) {
|
||||
func (db *DB) ExecStructContext(ctx context.Context, query string, st any) (sql.Result, error) {
|
||||
query, args, err := StructToSlice(query, st)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -258,7 +258,7 @@ func (db *DB) ExecStructContext(ctx context.Context, query string, st interface{
|
|||
}
|
||||
|
||||
// ExecContext exec query with args
|
||||
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
|
||||
func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) {
|
||||
hookCtx := contexts.NewContextHook(ctx, query, args)
|
||||
ctx, err := db.beforeProcess(hookCtx)
|
||||
if err != nil {
|
||||
|
|
@ -273,7 +273,7 @@ func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}
|
|||
}
|
||||
|
||||
// ExecStruct exec query with struct
|
||||
func (db *DB) ExecStruct(query string, st interface{}) (sql.Result, error) {
|
||||
func (db *DB) ExecStruct(query string, st any) (sql.Result, error) {
|
||||
return db.ExecStructContext(context.Background(), query, st)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ func BenchmarkSliceInterfaceQuery(b *testing.B) {
|
|||
}
|
||||
|
||||
for rows.Next() {
|
||||
slice := make([]interface{}, len(cols))
|
||||
slice := make([]any, len(cols))
|
||||
err = rows.ScanSlice(&slice)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
|
|
@ -394,7 +394,7 @@ func BenchmarkMapInterfaceQuery(b *testing.B) {
|
|||
}
|
||||
|
||||
for rows.Next() {
|
||||
m := make(map[string]interface{})
|
||||
m := make(map[string]any)
|
||||
err = rows.ScanMap(&m)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
|
|
@ -551,7 +551,7 @@ func BenchmarkExecMap(b *testing.B) {
|
|||
|
||||
b.StartTimer()
|
||||
|
||||
mp := map[string]interface{}{
|
||||
mp := map[string]any{
|
||||
"name": "xlw",
|
||||
"title": "tester",
|
||||
"age": 1.2,
|
||||
|
|
@ -582,7 +582,7 @@ func TestExecMap(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
mp := map[string]interface{}{
|
||||
mp := map[string]any{
|
||||
"name": "xlw",
|
||||
"title": "tester",
|
||||
"age": 1.2,
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ import (
|
|||
|
||||
// Queryer represents an interface to query a SQL to get data from database
|
||||
type Queryer interface {
|
||||
QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
|
||||
QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)
|
||||
}
|
||||
|
||||
// Executer represents an interface to execute a SQL
|
||||
type Executer interface {
|
||||
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
||||
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
|
||||
}
|
||||
|
||||
// QueryExecuter combines the Queryer and Executer
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ func (rs *Rows) ToMapString() ([]map[string]string, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var results = make([]map[string]string, 0, 10)
|
||||
results := make([]map[string]string, 0, 10)
|
||||
for rs.Next() {
|
||||
var record = make(map[string]string, len(cols))
|
||||
record := make(map[string]string, len(cols))
|
||||
err = rs.ScanMap(&record)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -37,7 +37,7 @@ func (rs *Rows) ToMapString() ([]map[string]string, error) {
|
|||
}
|
||||
|
||||
// ScanStructByIndex scan data to a struct's pointer according field index
|
||||
func (rs *Rows) ScanStructByIndex(dest ...interface{}) error {
|
||||
func (rs *Rows) ScanStructByIndex(dest ...any) error {
|
||||
if len(dest) == 0 {
|
||||
return errors.New("at least one struct")
|
||||
}
|
||||
|
|
@ -56,9 +56,9 @@ func (rs *Rows) ScanStructByIndex(dest ...interface{}) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newDest := make([]interface{}, len(cols))
|
||||
newDest := make([]any, len(cols))
|
||||
|
||||
var i = 0
|
||||
i := 0
|
||||
for _, vvv := range vvvs {
|
||||
for j := 0; j < vvv.NumField(); j++ {
|
||||
newDest[i] = vvv.Field(j).Addr().Interface()
|
||||
|
|
@ -97,7 +97,7 @@ func fieldByName(v reflect.Value, name string) reflect.Value {
|
|||
}
|
||||
|
||||
// ScanStructByName scan data to a struct's pointer according field name
|
||||
func (rs *Rows) ScanStructByName(dest interface{}) error {
|
||||
func (rs *Rows) ScanStructByName(dest any) error {
|
||||
vv := reflect.ValueOf(dest)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
|
||||
return errors.New("dest should be a struct's pointer")
|
||||
|
|
@ -108,7 +108,7 @@ func (rs *Rows) ScanStructByName(dest interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
newDest := make([]interface{}, len(cols))
|
||||
newDest := make([]any, len(cols))
|
||||
var v EmptyScanner
|
||||
for j, name := range cols {
|
||||
f := fieldByName(vv.Elem(), rs.db.Mapper.Table2Obj(name))
|
||||
|
|
@ -123,7 +123,7 @@ func (rs *Rows) ScanStructByName(dest interface{}) error {
|
|||
}
|
||||
|
||||
// ScanSlice scan data to a slice's pointer, slice's length should equal to columns' number
|
||||
func (rs *Rows) ScanSlice(dest interface{}) error {
|
||||
func (rs *Rows) ScanSlice(dest any) error {
|
||||
vv := reflect.ValueOf(dest)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Slice {
|
||||
return errors.New("dest should be a slice's pointer")
|
||||
|
|
@ -135,7 +135,7 @@ func (rs *Rows) ScanSlice(dest interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
newDest := make([]interface{}, len(cols))
|
||||
newDest := make([]any, len(cols))
|
||||
|
||||
for j := 0; j < len(cols); j++ {
|
||||
if j >= vvv.Len() {
|
||||
|
|
@ -158,7 +158,7 @@ func (rs *Rows) ScanSlice(dest interface{}) error {
|
|||
}
|
||||
|
||||
// ScanMap scan data to a map's pointer
|
||||
func (rs *Rows) ScanMap(dest interface{}) error {
|
||||
func (rs *Rows) ScanMap(dest any) error {
|
||||
vv := reflect.ValueOf(dest)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
|
||||
return errors.New("dest should be a map's pointer")
|
||||
|
|
@ -169,7 +169,7 @@ func (rs *Rows) ScanMap(dest interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
newDest := make([]interface{}, len(cols))
|
||||
newDest := make([]any, len(cols))
|
||||
vvv := vv.Elem()
|
||||
|
||||
for i := range cols {
|
||||
|
|
@ -217,7 +217,7 @@ func (row *Row) Columns() ([]string, error) {
|
|||
}
|
||||
|
||||
// Scan retrieves all row column values
|
||||
func (row *Row) Scan(dest ...interface{}) error {
|
||||
func (row *Row) Scan(dest ...any) error {
|
||||
if row.err != nil {
|
||||
return row.err
|
||||
}
|
||||
|
|
@ -244,7 +244,7 @@ func (row *Row) Scan(dest ...interface{}) error {
|
|||
}
|
||||
|
||||
// ScanStructByName retrieves all row column values into a struct
|
||||
func (row *Row) ScanStructByName(dest interface{}) error {
|
||||
func (row *Row) ScanStructByName(dest any) error {
|
||||
if row.err != nil {
|
||||
return row.err
|
||||
}
|
||||
|
|
@ -265,7 +265,7 @@ func (row *Row) ScanStructByName(dest interface{}) error {
|
|||
}
|
||||
|
||||
// ScanStructByIndex retrieves all row column values into a struct
|
||||
func (row *Row) ScanStructByIndex(dest interface{}) error {
|
||||
func (row *Row) ScanStructByIndex(dest any) error {
|
||||
if row.err != nil {
|
||||
return row.err
|
||||
}
|
||||
|
|
@ -286,7 +286,7 @@ func (row *Row) ScanStructByIndex(dest interface{}) error {
|
|||
}
|
||||
|
||||
// ScanSlice scan data to a slice's pointer, slice's length should equal to columns' number
|
||||
func (row *Row) ScanSlice(dest interface{}) error {
|
||||
func (row *Row) ScanSlice(dest any) error {
|
||||
if row.err != nil {
|
||||
return row.err
|
||||
}
|
||||
|
|
@ -308,7 +308,7 @@ func (row *Row) ScanSlice(dest interface{}) error {
|
|||
}
|
||||
|
||||
// ScanMap scan data to a map's pointer
|
||||
func (row *Row) ScanMap(dest interface{}) error {
|
||||
func (row *Row) ScanMap(dest any) error {
|
||||
if row.err != nil {
|
||||
return row.err
|
||||
}
|
||||
|
|
@ -336,7 +336,7 @@ func (row *Row) ToMapString() (map[string]string, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var record = make(map[string]string, len(cols))
|
||||
record := make(map[string]string, len(cols))
|
||||
err = row.ScanMap(&record)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -13,12 +13,10 @@ import (
|
|||
// NullTime defines a customize type NullTime
|
||||
type NullTime time.Time
|
||||
|
||||
var (
|
||||
_ driver.Valuer = NullTime{}
|
||||
)
|
||||
var _ driver.Valuer = NullTime{}
|
||||
|
||||
// Scan implements driver.Valuer
|
||||
func (ns *NullTime) Scan(value interface{}) error {
|
||||
func (ns *NullTime) Scan(value any) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -33,7 +31,7 @@ func (ns NullTime) Value() (driver.Value, error) {
|
|||
return (time.Time)(ns).Format("2006-01-02 15:04:05"), nil
|
||||
}
|
||||
|
||||
func convertTime(dest *NullTime, src interface{}) error {
|
||||
func convertTime(dest *NullTime, src any) error {
|
||||
// Common cases, without reflect.
|
||||
switch s := src.(type) {
|
||||
case string:
|
||||
|
|
@ -61,10 +59,9 @@ func convertTime(dest *NullTime, src interface{}) error {
|
|||
}
|
||||
|
||||
// EmptyScanner represents an empty scanner
|
||||
type EmptyScanner struct {
|
||||
}
|
||||
type EmptyScanner struct{}
|
||||
|
||||
// Scan implements
|
||||
func (EmptyScanner) Scan(src interface{}) error {
|
||||
func (EmptyScanner) Scan(src any) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ func (db *DB) Prepare(query string) (*Stmt, error) {
|
|||
}
|
||||
|
||||
// ExecMapContext execute with map
|
||||
func (s *Stmt) ExecMapContext(ctx context.Context, mp interface{}) (sql.Result, error) {
|
||||
func (s *Stmt) ExecMapContext(ctx context.Context, mp any) (sql.Result, error) {
|
||||
vv := reflect.ValueOf(mp)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
|
||||
return nil, errors.New("mp should be a map's pointer")
|
||||
}
|
||||
|
||||
args := make([]interface{}, len(s.names))
|
||||
args := make([]any, len(s.names))
|
||||
for k, i := range s.names {
|
||||
args[i] = vv.Elem().MapIndex(reflect.ValueOf(k)).Interface()
|
||||
}
|
||||
|
|
@ -63,18 +63,18 @@ func (s *Stmt) ExecMapContext(ctx context.Context, mp interface{}) (sql.Result,
|
|||
}
|
||||
|
||||
// ExecMap executes with map
|
||||
func (s *Stmt) ExecMap(mp interface{}) (sql.Result, error) {
|
||||
func (s *Stmt) ExecMap(mp any) (sql.Result, error) {
|
||||
return s.ExecMapContext(context.Background(), mp)
|
||||
}
|
||||
|
||||
// ExecStructContext executes with struct
|
||||
func (s *Stmt) ExecStructContext(ctx context.Context, st interface{}) (sql.Result, error) {
|
||||
func (s *Stmt) ExecStructContext(ctx context.Context, st any) (sql.Result, error) {
|
||||
vv := reflect.ValueOf(st)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
|
||||
return nil, errors.New("mp should be a map's pointer")
|
||||
}
|
||||
|
||||
args := make([]interface{}, len(s.names))
|
||||
args := make([]any, len(s.names))
|
||||
for k, i := range s.names {
|
||||
args[i] = vv.Elem().FieldByName(k).Interface()
|
||||
}
|
||||
|
|
@ -82,12 +82,12 @@ func (s *Stmt) ExecStructContext(ctx context.Context, st interface{}) (sql.Resul
|
|||
}
|
||||
|
||||
// ExecStruct executes with struct
|
||||
func (s *Stmt) ExecStruct(st interface{}) (sql.Result, error) {
|
||||
func (s *Stmt) ExecStruct(st any) (sql.Result, error) {
|
||||
return s.ExecStructContext(context.Background(), st)
|
||||
}
|
||||
|
||||
// ExecContext with args
|
||||
func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error) {
|
||||
func (s *Stmt) ExecContext(ctx context.Context, args ...any) (sql.Result, error) {
|
||||
hookCtx := contexts.NewContextHook(ctx, s.query, args)
|
||||
ctx, err := s.db.beforeProcess(hookCtx)
|
||||
if err != nil {
|
||||
|
|
@ -102,7 +102,7 @@ func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result
|
|||
}
|
||||
|
||||
// QueryContext query with args
|
||||
func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, error) {
|
||||
func (s *Stmt) QueryContext(ctx context.Context, args ...any) (*Rows, error) {
|
||||
hookCtx := contexts.NewContextHook(ctx, s.query, args)
|
||||
ctx, err := s.db.beforeProcess(hookCtx)
|
||||
if err != nil {
|
||||
|
|
@ -117,18 +117,18 @@ func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, er
|
|||
}
|
||||
|
||||
// Query query with args
|
||||
func (s *Stmt) Query(args ...interface{}) (*Rows, error) {
|
||||
func (s *Stmt) Query(args ...any) (*Rows, error) {
|
||||
return s.QueryContext(context.Background(), args...)
|
||||
}
|
||||
|
||||
// QueryMapContext query with map
|
||||
func (s *Stmt) QueryMapContext(ctx context.Context, mp interface{}) (*Rows, error) {
|
||||
func (s *Stmt) QueryMapContext(ctx context.Context, mp any) (*Rows, error) {
|
||||
vv := reflect.ValueOf(mp)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
|
||||
return nil, errors.New("mp should be a map's pointer")
|
||||
}
|
||||
|
||||
args := make([]interface{}, len(s.names))
|
||||
args := make([]any, len(s.names))
|
||||
for k, i := range s.names {
|
||||
args[i] = vv.Elem().MapIndex(reflect.ValueOf(k)).Interface()
|
||||
}
|
||||
|
|
@ -137,18 +137,18 @@ func (s *Stmt) QueryMapContext(ctx context.Context, mp interface{}) (*Rows, erro
|
|||
}
|
||||
|
||||
// QueryMap query with map
|
||||
func (s *Stmt) QueryMap(mp interface{}) (*Rows, error) {
|
||||
func (s *Stmt) QueryMap(mp any) (*Rows, error) {
|
||||
return s.QueryMapContext(context.Background(), mp)
|
||||
}
|
||||
|
||||
// QueryStructContext query with struct
|
||||
func (s *Stmt) QueryStructContext(ctx context.Context, st interface{}) (*Rows, error) {
|
||||
func (s *Stmt) QueryStructContext(ctx context.Context, st any) (*Rows, error) {
|
||||
vv := reflect.ValueOf(st)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
|
||||
return nil, errors.New("mp should be a map's pointer")
|
||||
}
|
||||
|
||||
args := make([]interface{}, len(s.names))
|
||||
args := make([]any, len(s.names))
|
||||
for k, i := range s.names {
|
||||
args[i] = vv.Elem().FieldByName(k).Interface()
|
||||
}
|
||||
|
|
@ -157,29 +157,29 @@ func (s *Stmt) QueryStructContext(ctx context.Context, st interface{}) (*Rows, e
|
|||
}
|
||||
|
||||
// QueryStruct query with struct
|
||||
func (s *Stmt) QueryStruct(st interface{}) (*Rows, error) {
|
||||
func (s *Stmt) QueryStruct(st any) (*Rows, error) {
|
||||
return s.QueryStructContext(context.Background(), st)
|
||||
}
|
||||
|
||||
// QueryRowContext query row with args
|
||||
func (s *Stmt) QueryRowContext(ctx context.Context, args ...interface{}) *Row {
|
||||
func (s *Stmt) QueryRowContext(ctx context.Context, args ...any) *Row {
|
||||
rows, err := s.QueryContext(ctx, args...)
|
||||
return &Row{rows, err}
|
||||
}
|
||||
|
||||
// QueryRow query row with args
|
||||
func (s *Stmt) QueryRow(args ...interface{}) *Row {
|
||||
func (s *Stmt) QueryRow(args ...any) *Row {
|
||||
return s.QueryRowContext(context.Background(), args...)
|
||||
}
|
||||
|
||||
// QueryRowMapContext query row with map
|
||||
func (s *Stmt) QueryRowMapContext(ctx context.Context, mp interface{}) *Row {
|
||||
func (s *Stmt) QueryRowMapContext(ctx context.Context, mp any) *Row {
|
||||
vv := reflect.ValueOf(mp)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
|
||||
return &Row{nil, errors.New("mp should be a map's pointer")}
|
||||
}
|
||||
|
||||
args := make([]interface{}, len(s.names))
|
||||
args := make([]any, len(s.names))
|
||||
for k, i := range s.names {
|
||||
args[i] = vv.Elem().MapIndex(reflect.ValueOf(k)).Interface()
|
||||
}
|
||||
|
|
@ -188,18 +188,18 @@ func (s *Stmt) QueryRowMapContext(ctx context.Context, mp interface{}) *Row {
|
|||
}
|
||||
|
||||
// QueryRowMap query row with map
|
||||
func (s *Stmt) QueryRowMap(mp interface{}) *Row {
|
||||
func (s *Stmt) QueryRowMap(mp any) *Row {
|
||||
return s.QueryRowMapContext(context.Background(), mp)
|
||||
}
|
||||
|
||||
// QueryRowStructContext query row with struct
|
||||
func (s *Stmt) QueryRowStructContext(ctx context.Context, st interface{}) *Row {
|
||||
func (s *Stmt) QueryRowStructContext(ctx context.Context, st any) *Row {
|
||||
vv := reflect.ValueOf(st)
|
||||
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
|
||||
return &Row{nil, errors.New("st should be a struct's pointer")}
|
||||
}
|
||||
|
||||
args := make([]interface{}, len(s.names))
|
||||
args := make([]any, len(s.names))
|
||||
for k, i := range s.names {
|
||||
args[i] = vv.Elem().FieldByName(k).Interface()
|
||||
}
|
||||
|
|
@ -208,6 +208,6 @@ func (s *Stmt) QueryRowStructContext(ctx context.Context, st interface{}) *Row {
|
|||
}
|
||||
|
||||
// QueryRowStruct query row with struct
|
||||
func (s *Stmt) QueryRowStruct(st interface{}) *Row {
|
||||
func (s *Stmt) QueryRowStruct(st any) *Row {
|
||||
return s.QueryRowStructContext(context.Background(), st)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ func (tx *Tx) Stmt(stmt *Stmt) *Stmt {
|
|||
}
|
||||
|
||||
// ExecMapContext executes query with args in a map
|
||||
func (tx *Tx) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error) {
|
||||
func (tx *Tx) ExecMapContext(ctx context.Context, query string, mp any) (sql.Result, error) {
|
||||
query, args, err := MapToSlice(query, mp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -112,12 +112,12 @@ func (tx *Tx) ExecMapContext(ctx context.Context, query string, mp interface{})
|
|||
}
|
||||
|
||||
// ExecMap executes query with args in a map
|
||||
func (tx *Tx) ExecMap(query string, mp interface{}) (sql.Result, error) {
|
||||
func (tx *Tx) ExecMap(query string, mp any) (sql.Result, error) {
|
||||
return tx.ExecMapContext(context.Background(), query, mp)
|
||||
}
|
||||
|
||||
// ExecStructContext executes query with args in a struct
|
||||
func (tx *Tx) ExecStructContext(ctx context.Context, query string, st interface{}) (sql.Result, error) {
|
||||
func (tx *Tx) ExecStructContext(ctx context.Context, query string, st any) (sql.Result, error) {
|
||||
query, args, err := StructToSlice(query, st)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -126,7 +126,7 @@ func (tx *Tx) ExecStructContext(ctx context.Context, query string, st interface{
|
|||
}
|
||||
|
||||
// ExecContext executes a query with args
|
||||
func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
|
||||
func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) {
|
||||
hookCtx := contexts.NewContextHook(ctx, query, args)
|
||||
ctx, err := tx.db.beforeProcess(hookCtx)
|
||||
if err != nil {
|
||||
|
|
@ -141,12 +141,12 @@ func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}
|
|||
}
|
||||
|
||||
// ExecStruct executes query with args in a struct
|
||||
func (tx *Tx) ExecStruct(query string, st interface{}) (sql.Result, error) {
|
||||
func (tx *Tx) ExecStruct(query string, st any) (sql.Result, error) {
|
||||
return tx.ExecStructContext(context.Background(), query, st)
|
||||
}
|
||||
|
||||
// QueryContext query with args
|
||||
func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
|
||||
func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error) {
|
||||
hookCtx := contexts.NewContextHook(ctx, query, args)
|
||||
ctx, err := tx.db.beforeProcess(hookCtx)
|
||||
if err != nil {
|
||||
|
|
@ -164,12 +164,12 @@ func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{
|
|||
}
|
||||
|
||||
// Query query with args
|
||||
func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error) {
|
||||
func (tx *Tx) Query(query string, args ...any) (*Rows, error) {
|
||||
return tx.QueryContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
// QueryMapContext query with args in a map
|
||||
func (tx *Tx) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error) {
|
||||
func (tx *Tx) QueryMapContext(ctx context.Context, query string, mp any) (*Rows, error) {
|
||||
query, args, err := MapToSlice(query, mp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -178,12 +178,12 @@ func (tx *Tx) QueryMapContext(ctx context.Context, query string, mp interface{})
|
|||
}
|
||||
|
||||
// QueryMap query with args in a map
|
||||
func (tx *Tx) QueryMap(query string, mp interface{}) (*Rows, error) {
|
||||
func (tx *Tx) QueryMap(query string, mp any) (*Rows, error) {
|
||||
return tx.QueryMapContext(context.Background(), query, mp)
|
||||
}
|
||||
|
||||
// QueryStructContext query with args in struct
|
||||
func (tx *Tx) QueryStructContext(ctx context.Context, query string, st interface{}) (*Rows, error) {
|
||||
func (tx *Tx) QueryStructContext(ctx context.Context, query string, st any) (*Rows, error) {
|
||||
query, args, err := StructToSlice(query, st)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -192,23 +192,23 @@ func (tx *Tx) QueryStructContext(ctx context.Context, query string, st interface
|
|||
}
|
||||
|
||||
// QueryStruct query with args in struct
|
||||
func (tx *Tx) QueryStruct(query string, st interface{}) (*Rows, error) {
|
||||
func (tx *Tx) QueryStruct(query string, st any) (*Rows, error) {
|
||||
return tx.QueryStructContext(context.Background(), query, st)
|
||||
}
|
||||
|
||||
// QueryRowContext query one row with args
|
||||
func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row {
|
||||
func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...any) *Row {
|
||||
rows, err := tx.QueryContext(ctx, query, args...)
|
||||
return &Row{rows, err}
|
||||
}
|
||||
|
||||
// QueryRow query one row with args
|
||||
func (tx *Tx) QueryRow(query string, args ...interface{}) *Row {
|
||||
func (tx *Tx) QueryRow(query string, args ...any) *Row {
|
||||
return tx.QueryRowContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
// QueryRowMapContext query one row with args in a map
|
||||
func (tx *Tx) QueryRowMapContext(ctx context.Context, query string, mp interface{}) *Row {
|
||||
func (tx *Tx) QueryRowMapContext(ctx context.Context, query string, mp any) *Row {
|
||||
query, args, err := MapToSlice(query, mp)
|
||||
if err != nil {
|
||||
return &Row{nil, err}
|
||||
|
|
@ -217,12 +217,12 @@ func (tx *Tx) QueryRowMapContext(ctx context.Context, query string, mp interface
|
|||
}
|
||||
|
||||
// QueryRowMap query one row with args in a map
|
||||
func (tx *Tx) QueryRowMap(query string, mp interface{}) *Row {
|
||||
func (tx *Tx) QueryRowMap(query string, mp any) *Row {
|
||||
return tx.QueryRowMapContext(context.Background(), query, mp)
|
||||
}
|
||||
|
||||
// QueryRowStructContext query one row with args in struct
|
||||
func (tx *Tx) QueryRowStructContext(ctx context.Context, query string, st interface{}) *Row {
|
||||
func (tx *Tx) QueryRowStructContext(ctx context.Context, query string, st any) *Row {
|
||||
query, args, err := StructToSlice(query, st)
|
||||
if err != nil {
|
||||
return &Row{nil, err}
|
||||
|
|
@ -231,6 +231,6 @@ func (tx *Tx) QueryRowStructContext(ctx context.Context, query string, st interf
|
|||
}
|
||||
|
||||
// QueryRowStruct query one row with args in struct
|
||||
func (tx *Tx) QueryRowStruct(query string, st interface{}) *Row {
|
||||
func (tx *Tx) QueryRowStruct(query string, st any) *Row {
|
||||
return tx.QueryRowStructContext(context.Background(), query, st)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ func init() {
|
|||
type GOjson struct{}
|
||||
|
||||
// Marshal implements JSONInterface
|
||||
func (GOjson) Marshal(v interface{}) ([]byte, error) {
|
||||
func (GOjson) Marshal(v any) ([]byte, error) {
|
||||
return gojson.Marshal(v)
|
||||
}
|
||||
|
||||
// Unmarshal implements JSONInterface
|
||||
func (GOjson) Unmarshal(data []byte, v interface{}) error {
|
||||
func (GOjson) Unmarshal(data []byte, v any) error {
|
||||
return gojson.Unmarshal(data, v)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,24 +8,22 @@ import "encoding/json"
|
|||
|
||||
// Interface represents an interface to handle json data
|
||||
type Interface interface {
|
||||
Marshal(v interface{}) ([]byte, error)
|
||||
Unmarshal(data []byte, v interface{}) error
|
||||
Marshal(v any) ([]byte, error)
|
||||
Unmarshal(data []byte, v any) error
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultJSONHandler default json handler
|
||||
DefaultJSONHandler Interface = StdJSON{}
|
||||
)
|
||||
// DefaultJSONHandler default json handler
|
||||
var DefaultJSONHandler Interface = StdJSON{}
|
||||
|
||||
// StdJSON implements JSONInterface via encoding/json
|
||||
type StdJSON struct{}
|
||||
|
||||
// Marshal implements JSONInterface
|
||||
func (StdJSON) Marshal(v interface{}) ([]byte, error) {
|
||||
func (StdJSON) Marshal(v any) ([]byte, error) {
|
||||
return json.Marshal(v)
|
||||
}
|
||||
|
||||
// Unmarshal implements JSONInterface
|
||||
func (StdJSON) Unmarshal(data []byte, v interface{}) error {
|
||||
func (StdJSON) Unmarshal(data []byte, v any) error {
|
||||
return json.Unmarshal(data, v)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ func init() {
|
|||
type JSONiter struct{}
|
||||
|
||||
// Marshal implements JSONInterface
|
||||
func (JSONiter) Marshal(v interface{}) ([]byte, error) {
|
||||
func (JSONiter) Marshal(v any) ([]byte, error) {
|
||||
return jsoniter.Marshal(v)
|
||||
}
|
||||
|
||||
// Unmarshal implements JSONInterface
|
||||
func (JSONiter) Unmarshal(data []byte, v interface{}) error {
|
||||
func (JSONiter) Unmarshal(data []byte, v any) error {
|
||||
return jsoniter.Unmarshal(data, v)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// WriteArg writes an arg
|
||||
func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) error {
|
||||
func (statement *Statement) WriteArg(w *builder.BytesWriter, arg any) error {
|
||||
switch argv := arg.(type) {
|
||||
case *builder.Builder:
|
||||
if _, err := w.WriteString("("); err != nil {
|
||||
|
|
@ -40,7 +40,7 @@ func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) er
|
|||
}
|
||||
|
||||
// WriteArgs writes args
|
||||
func (statement *Statement) WriteArgs(w *builder.BytesWriter, args []interface{}) error {
|
||||
func (statement *Statement) WriteArgs(w *builder.BytesWriter, args []any) error {
|
||||
for i, arg := range args {
|
||||
if err := statement.WriteArg(w, arg); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
// Copyright 2019 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package statements
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm/v2/internal/utils"
|
||||
"xorm.io/xorm/v2/schemas"
|
||||
)
|
||||
|
||||
// ConvertIDSQL converts SQL with id
|
||||
func (statement *Statement) ConvertIDSQL(sqlStr string) string {
|
||||
if statement.RefTable != nil {
|
||||
cols := statement.RefTable.PKColumns()
|
||||
if len(cols) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
colstrs := statement.joinColumns(cols, false)
|
||||
sqls := utils.SplitNNoCase(sqlStr, " from ", 2)
|
||||
if len(sqls) != 2 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString("SELECT ")
|
||||
pLimitN := statement.LimitN
|
||||
if pLimitN != nil && statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
b.WriteString("TOP ")
|
||||
b.WriteString(strconv.Itoa(*pLimitN))
|
||||
b.WriteString(" ")
|
||||
}
|
||||
b.WriteString(colstrs)
|
||||
b.WriteString(" FROM ")
|
||||
b.WriteString(sqls[1])
|
||||
|
||||
return b.String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ConvertUpdateSQL converts update SQL
|
||||
func (statement *Statement) ConvertUpdateSQL(sqlStr string) (string, string) {
|
||||
if statement.RefTable == nil || len(statement.RefTable.PrimaryKeys) != 1 {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
colstrs := statement.joinColumns(statement.RefTable.PKColumns(), true)
|
||||
sqls := utils.SplitNNoCase(sqlStr, "where", 2)
|
||||
if len(sqls) != 2 {
|
||||
if len(sqls) == 1 {
|
||||
return sqls[0], fmt.Sprintf("SELECT %v FROM %v",
|
||||
colstrs, statement.quote(statement.TableName()))
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
whereStr := sqls[1]
|
||||
|
||||
// TODO: for postgres only, if any other database?
|
||||
var paraStr string
|
||||
if statement.dialect.URI().DBType == schemas.POSTGRES {
|
||||
paraStr = "$"
|
||||
} else if statement.dialect.URI().DBType == schemas.MSSQL {
|
||||
paraStr = ":"
|
||||
}
|
||||
|
||||
if paraStr != "" {
|
||||
if strings.Contains(sqls[1], paraStr) {
|
||||
dollers := strings.Split(sqls[1], paraStr)
|
||||
whereStr = dollers[0]
|
||||
for i, c := range dollers[1:] {
|
||||
ccs := strings.SplitN(c, " ", 2)
|
||||
whereStr += fmt.Sprintf(paraStr+"%v %v", i+1, ccs[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sqls[0], fmt.Sprintf("SELECT %v FROM %v WHERE %v",
|
||||
colstrs, statement.quote(statement.TableName()),
|
||||
whereStr)
|
||||
}
|
||||
|
|
@ -27,17 +27,17 @@ func (statement *Statement) QuoteReplacer(w *builder.BytesWriter) *QuoteReplacer
|
|||
}
|
||||
|
||||
// Where add Where statement
|
||||
func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement {
|
||||
func (statement *Statement) Where(query any, args ...any) *Statement {
|
||||
return statement.And(query, args...)
|
||||
}
|
||||
|
||||
// And add Where & and statement
|
||||
func (statement *Statement) And(query interface{}, args ...interface{}) *Statement {
|
||||
func (statement *Statement) And(query any, args ...any) *Statement {
|
||||
switch qr := query.(type) {
|
||||
case string:
|
||||
cond := builder.Expr(qr, args...)
|
||||
statement.cond = statement.cond.And(cond)
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
cond := make(builder.Eq)
|
||||
for k, v := range qr {
|
||||
cond[statement.quote(k)] = v
|
||||
|
|
@ -58,12 +58,12 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
|
|||
}
|
||||
|
||||
// Or add Where & Or statement
|
||||
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
||||
func (statement *Statement) Or(query any, args ...any) *Statement {
|
||||
switch qr := query.(type) {
|
||||
case string:
|
||||
cond := builder.Expr(qr, args...)
|
||||
statement.cond = statement.cond.Or(cond)
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
cond := make(builder.Eq)
|
||||
for k, v := range qr {
|
||||
cond[statement.quote(k)] = v
|
||||
|
|
@ -83,14 +83,14 @@ func (statement *Statement) Or(query interface{}, args ...interface{}) *Statemen
|
|||
}
|
||||
|
||||
// In generate "Where column IN (?) " statement
|
||||
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||
func (statement *Statement) In(column string, args ...any) *Statement {
|
||||
in := builder.In(statement.quote(column), args...)
|
||||
statement.cond = statement.cond.And(in)
|
||||
return statement
|
||||
}
|
||||
|
||||
// NotIn generate "Where column NOT IN (?) " statement
|
||||
func (statement *Statement) NotIn(column string, args ...interface{}) *Statement {
|
||||
func (statement *Statement) NotIn(column string, args ...any) *Statement {
|
||||
notIn := builder.NotIn(statement.quote(column), args...)
|
||||
statement.cond = statement.cond.And(notIn)
|
||||
return statement
|
||||
|
|
|
|||
|
|
@ -84,10 +84,11 @@ func (statement *Statement) writeOrderCond(orderCondWriter *builder.BytesWriter,
|
|||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) WriteDelete(realSQLWriter, deleteSQLWriter *builder.BytesWriter, nowTime func(*schemas.Column) (interface{}, time.Time, error)) error {
|
||||
func (statement *Statement) WriteDelete(realSQLWriter *builder.BytesWriter, nowTime func(*schemas.Column) (any, time.Time, error)) error {
|
||||
tableNameNoQuote := statement.TableName()
|
||||
tableName := statement.dialect.Quoter().Quote(tableNameNoQuote)
|
||||
table := statement.RefTable
|
||||
deleteSQLWriter := builder.NewWriter()
|
||||
if _, err := fmt.Fprint(deleteSQLWriter, "DELETE FROM ", tableName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func (err ErrUnsupportedExprType) Error() string {
|
|||
// Expr represents an SQL express
|
||||
type Expr struct {
|
||||
ColName string
|
||||
Arg interface{}
|
||||
Arg any
|
||||
}
|
||||
|
||||
// WriteArgs writes args to the writer
|
||||
|
|
@ -66,7 +66,7 @@ func (exprs exprParams) ColNames() []string {
|
|||
return cols
|
||||
}
|
||||
|
||||
func (exprs *exprParams) Add(name string, arg interface{}) {
|
||||
func (exprs *exprParams) Add(name string, arg any) {
|
||||
*exprs = append(*exprs, Expr{name, arg})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func (statement *Statement) writeInsertOutput(buf *strings.Builder, table *schem
|
|||
}
|
||||
|
||||
// GenInsertSQL generates insert beans SQL
|
||||
func (statement *Statement) GenInsertSQL(colNames []string, args []interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenInsertSQL(colNames []string, args []any) (string, []any, error) {
|
||||
var (
|
||||
buf = builder.NewWriter()
|
||||
exprs = statement.ExprColumns
|
||||
|
|
@ -177,7 +177,7 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
|
|||
}
|
||||
|
||||
// GenInsertMapSQL generates insert map SQL
|
||||
func (statement *Statement) GenInsertMapSQL(columns []string, args []interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenInsertMapSQL(columns []string, args []any) (string, []any, error) {
|
||||
var (
|
||||
buf = builder.NewWriter()
|
||||
exprs = statement.ExprColumns
|
||||
|
|
@ -242,7 +242,7 @@ func (statement *Statement) GenInsertMapSQL(columns []string, args []interface{}
|
|||
return buf.String(), buf.Args(), nil
|
||||
}
|
||||
|
||||
func (statement *Statement) GenInsertMultipleMapSQL(columns []string, argss [][]interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenInsertMultipleMapSQL(columns []string, argss [][]any) (string, []any, error) {
|
||||
var (
|
||||
buf = builder.NewWriter()
|
||||
exprs = statement.ExprColumns
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
// Join The joinOP should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
|
||||
func (statement *Statement) Join(joinOP string, joinTable interface{}, condition interface{}, args ...interface{}) *Statement {
|
||||
func (statement *Statement) Join(joinOP string, joinTable any, condition any, args ...any) *Statement {
|
||||
statement.joins = append(statement.joins, join{
|
||||
op: joinOP,
|
||||
table: joinTable,
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import (
|
|||
)
|
||||
|
||||
type orderBy struct {
|
||||
orderStr interface{}
|
||||
orderArgs []interface{}
|
||||
orderStr any
|
||||
orderArgs []any
|
||||
direction string // ASC, DESC or "", "" means raw orderStr
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ func (statement *Statement) writeOrderBys(w *builder.BytesWriter) error {
|
|||
}
|
||||
|
||||
// OrderBy generate "Order By order" statement
|
||||
func (statement *Statement) OrderBy(order interface{}, args ...interface{}) *Statement {
|
||||
func (statement *Statement) OrderBy(order any, args ...any) *Statement {
|
||||
ob := orderBy{order, args, ""}
|
||||
if err := ob.CheckValid(); err != nil {
|
||||
statement.LastError = err
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func IsIDConditionWithNoTableErr(err error) bool {
|
|||
}
|
||||
|
||||
// ID generate "where id = ? " statement or for composite key "where key1 = ? and key2 = ?"
|
||||
func (statement *Statement) ID(id interface{}) *Statement {
|
||||
func (statement *Statement) ID(id any) *Statement {
|
||||
switch t := id.(type) {
|
||||
case *schemas.PK:
|
||||
statement.idParam = *t
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
// GenQuerySQL generate query SQL
|
||||
func (statement *Statement) GenQuerySQL(sqlOrArgs ...interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenQuerySQL(sqlOrArgs ...any) (string, []any, error) {
|
||||
if len(sqlOrArgs) > 0 {
|
||||
return statement.ConvertSQLOrArgs(sqlOrArgs...)
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ func (statement *Statement) GenQuerySQL(sqlOrArgs ...interface{}) (string, []int
|
|||
}
|
||||
|
||||
// GenSumSQL generates sum SQL
|
||||
func (statement *Statement) GenSumSQL(bean interface{}, columns ...string) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenSumSQL(bean any, columns ...string) (string, []any, error) {
|
||||
if statement.RawSQL != "" {
|
||||
return statement.GenRawSQL(), statement.RawParams, nil
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ func (statement *Statement) GenSumSQL(bean interface{}, columns ...string) (stri
|
|||
}
|
||||
|
||||
// GenGetSQL generates Get SQL
|
||||
func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenGetSQL(bean any) (string, []any, error) {
|
||||
var isStruct bool
|
||||
if bean != nil {
|
||||
v := rValue(bean)
|
||||
|
|
@ -127,7 +127,7 @@ func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{},
|
|||
}
|
||||
|
||||
// GenCountSQL generates the SQL for counting
|
||||
func (statement *Statement) GenCountSQL(beans ...interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenCountSQL(beans ...any) (string, []any, error) {
|
||||
if statement.RawSQL != "" {
|
||||
return statement.GenRawSQL(), statement.RawParams, nil
|
||||
}
|
||||
|
|
@ -286,12 +286,12 @@ func (statement *Statement) writeSelect(buf *builder.BytesWriter, columnStr stri
|
|||
}
|
||||
|
||||
// GenExistSQL generates Exist SQL
|
||||
func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenExistSQL(bean ...any) (string, []any, error) {
|
||||
if statement.RawSQL != "" {
|
||||
return statement.GenRawSQL(), statement.RawParams, nil
|
||||
}
|
||||
|
||||
var b interface{}
|
||||
var b any
|
||||
if len(bean) > 0 {
|
||||
b = bean[0]
|
||||
beanValue := reflect.ValueOf(bean[0])
|
||||
|
|
@ -393,7 +393,7 @@ func (statement *Statement) genSelectColumnStr() string {
|
|||
}
|
||||
|
||||
// GenFindSQL generates Find SQL
|
||||
func (statement *Statement) GenFindSQL(autoCond builder.Cond) (string, []interface{}, error) {
|
||||
func (statement *Statement) GenFindSQL(autoCond builder.Cond) (string, []any, error) {
|
||||
if statement.RawSQL != "" {
|
||||
return statement.GenRawSQL(), statement.RawParams, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ var (
|
|||
|
||||
type join struct {
|
||||
op string
|
||||
table interface{}
|
||||
condition interface{}
|
||||
args []interface{}
|
||||
table any
|
||||
condition any
|
||||
args []any
|
||||
}
|
||||
|
||||
// Statement save all the sql info for executing SQL
|
||||
|
|
@ -59,7 +59,7 @@ type Statement struct {
|
|||
AltTableName string
|
||||
tableName string
|
||||
RawSQL string
|
||||
RawParams []interface{}
|
||||
RawParams []any
|
||||
UseCascade bool
|
||||
UseAutoJoin bool
|
||||
StoreEngine string
|
||||
|
|
@ -136,7 +136,7 @@ func (statement *Statement) Reset() {
|
|||
statement.tableName = ""
|
||||
statement.idParam = nil
|
||||
statement.RawSQL = ""
|
||||
statement.RawParams = make([]interface{}, 0)
|
||||
statement.RawParams = make([]any, 0)
|
||||
statement.UseAutoTime = true
|
||||
statement.NoAutoCondition = false
|
||||
statement.IsDistinct = false
|
||||
|
|
@ -159,7 +159,7 @@ func (statement *Statement) Reset() {
|
|||
}
|
||||
|
||||
// SQL adds raw sql statement
|
||||
func (statement *Statement) SQL(query interface{}, args ...interface{}) *Statement {
|
||||
func (statement *Statement) SQL(query any, args ...any) *Statement {
|
||||
switch t := query.(type) {
|
||||
case (*builder.Builder):
|
||||
var err error
|
||||
|
|
@ -192,12 +192,12 @@ func (statement *Statement) SetRefValue(v reflect.Value) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func rValue(bean interface{}) reflect.Value {
|
||||
func rValue(bean any) reflect.Value {
|
||||
return reflect.Indirect(reflect.ValueOf(bean))
|
||||
}
|
||||
|
||||
// SetRefBean set ref bean
|
||||
func (statement *Statement) SetRefBean(bean interface{}) error {
|
||||
func (statement *Statement) SetRefBean(bean any) error {
|
||||
var err error
|
||||
statement.RefTable, err = statement.tagParser.ParseWithCache(rValue(bean))
|
||||
if err != nil {
|
||||
|
|
@ -212,7 +212,7 @@ func (statement *Statement) NeedTableName() bool {
|
|||
}
|
||||
|
||||
// Incr Generate "Update ... Set column = column + arg" statement
|
||||
func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
||||
func (statement *Statement) Incr(column string, arg ...any) *Statement {
|
||||
if len(arg) > 0 {
|
||||
statement.IncrColumns.Add(column, arg[0])
|
||||
} else {
|
||||
|
|
@ -222,7 +222,7 @@ func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
|||
}
|
||||
|
||||
// Decr Generate "Update ... Set column = column - arg" statement
|
||||
func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
||||
func (statement *Statement) Decr(column string, arg ...any) *Statement {
|
||||
if len(arg) > 0 {
|
||||
statement.DecrColumns.Add(column, arg[0])
|
||||
} else {
|
||||
|
|
@ -232,7 +232,7 @@ func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
|||
}
|
||||
|
||||
// SetExpr Generate "Update ... Set column = {expression}" statement
|
||||
func (statement *Statement) SetExpr(column string, expression interface{}) *Statement {
|
||||
func (statement *Statement) SetExpr(column string, expression any) *Statement {
|
||||
if e, ok := expression.(string); ok {
|
||||
statement.ExprColumns.Add(column, statement.dialect.Quoter().Replace(e))
|
||||
} else {
|
||||
|
|
@ -271,7 +271,7 @@ func (statement *Statement) Limit(limit int, start ...int) *Statement {
|
|||
}
|
||||
|
||||
// SetTable tempororily set table name, the parameter could be a string or a pointer of struct
|
||||
func (statement *Statement) SetTable(tableNameOrBean interface{}) error {
|
||||
func (statement *Statement) SetTable(tableNameOrBean any) error {
|
||||
v := rValue(tableNameOrBean)
|
||||
t := v.Type()
|
||||
if t.Kind() == reflect.Struct {
|
||||
|
|
@ -365,7 +365,7 @@ func (statement *Statement) GenDelIndexSQL() []string {
|
|||
return sqls
|
||||
}
|
||||
|
||||
func (statement *Statement) asDBCond(fieldValue reflect.Value, fieldType reflect.Type, col *schemas.Column, allUseBool, requiredField bool) (interface{}, bool, error) {
|
||||
func (statement *Statement) asDBCond(fieldValue reflect.Value, fieldType reflect.Type, col *schemas.Column, allUseBool, requiredField bool) (any, bool, error) {
|
||||
switch fieldType.Kind() {
|
||||
case reflect.Ptr:
|
||||
if fieldValue.IsNil() {
|
||||
|
|
@ -501,7 +501,7 @@ func (statement *Statement) asDBCond(fieldValue reflect.Value, fieldType reflect
|
|||
return fieldValue.Interface(), true, nil
|
||||
}
|
||||
|
||||
func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
|
||||
func (statement *Statement) buildConds2(table *schemas.Table, bean any,
|
||||
includeVersion bool, includeUpdated bool, includeNil bool,
|
||||
includeAutoIncr bool, allUseBool bool, useAllCols bool, unscoped bool,
|
||||
mustColumnMap map[string]bool, tableName, aliasName string, addedTableName bool,
|
||||
|
|
@ -599,13 +599,13 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
|
|||
}
|
||||
|
||||
// BuildConds builds condition
|
||||
func (statement *Statement) BuildConds(table *schemas.Table, bean interface{}, includeVersion bool, includeUpdated bool, includeNil bool, includeAutoIncr bool, addedTableName bool) (builder.Cond, error) {
|
||||
func (statement *Statement) BuildConds(table *schemas.Table, bean any, includeVersion bool, includeUpdated bool, includeNil bool, includeAutoIncr bool, addedTableName bool) (builder.Cond, error) {
|
||||
return statement.buildConds2(table, bean, includeVersion, includeUpdated, includeNil, includeAutoIncr, statement.allUseBool, statement.useAllCols,
|
||||
statement.unscoped, statement.MustColumnMap, statement.TableName(), statement.TableAlias, addedTableName)
|
||||
}
|
||||
|
||||
// MergeConds merge conditions from bean and id
|
||||
func (statement *Statement) MergeConds(bean interface{}) error {
|
||||
func (statement *Statement) MergeConds(bean any) error {
|
||||
if !statement.NoAutoCondition && statement.RefTable != nil {
|
||||
addedTableName := (len(statement.joins) > 0)
|
||||
autoCond, err := statement.BuildConds(statement.RefTable, bean, true, true, false, true, addedTableName)
|
||||
|
|
@ -624,7 +624,7 @@ func (statement *Statement) quoteColumnStr(columnStr string) string {
|
|||
}
|
||||
|
||||
// ConvertSQLOrArgs converts sql or args
|
||||
func (statement *Statement) ConvertSQLOrArgs(sqlOrArgs ...interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) ConvertSQLOrArgs(sqlOrArgs ...any) (string, []any, error) {
|
||||
sql, args, err := statement.convertSQLOrArgs(sqlOrArgs...)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
|
|
@ -632,11 +632,11 @@ func (statement *Statement) ConvertSQLOrArgs(sqlOrArgs ...interface{}) (string,
|
|||
return statement.ReplaceQuote(sql), args, nil
|
||||
}
|
||||
|
||||
func (statement *Statement) convertSQLOrArgs(sqlOrArgs ...interface{}) (string, []interface{}, error) {
|
||||
func (statement *Statement) convertSQLOrArgs(sqlOrArgs ...any) (string, []any, error) {
|
||||
switch sqlOrArgs[0].(type) {
|
||||
case string:
|
||||
if len(sqlOrArgs) > 1 {
|
||||
newArgs := make([]interface{}, 0, len(sqlOrArgs)-1)
|
||||
newArgs := make([]any, 0, len(sqlOrArgs)-1)
|
||||
for _, arg := range sqlOrArgs[1:] {
|
||||
if v, ok := arg.(time.Time); ok {
|
||||
newArgs = append(newArgs, v.In(statement.defaultTimeZone).Format("2006-01-02 15:04:05"))
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func TestConvertSQLOrArgs(t *testing.T) {
|
|||
// ID int
|
||||
// del *time.Time `xorm:"deleted"`
|
||||
// }
|
||||
args := []interface{}{
|
||||
args := []any{
|
||||
"INSERT `table` (`id`, `del`) VALUES (?, ?)", 1, (*time.Time)(nil),
|
||||
}
|
||||
// before fix, here will panic
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func (statement *Statement) ifAddColUpdate(col *schemas.Column, includeVersion,
|
|||
func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
||||
includeVersion, includeUpdated, includeNil,
|
||||
includeAutoIncr, update bool,
|
||||
) ([]string, []interface{}, error) {
|
||||
) ([]string, []any, error) {
|
||||
table := statement.RefTable
|
||||
allUseBool := statement.allUseBool
|
||||
useAllCols := statement.useAllCols
|
||||
|
|
@ -75,7 +75,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
|||
nullableMap := statement.NullableMap
|
||||
|
||||
colNames := make([]string, 0)
|
||||
args := make([]interface{}, 0)
|
||||
args := make([]any, 0)
|
||||
|
||||
for _, col := range table.Columns() {
|
||||
ok, err := statement.ifAddColUpdate(col, includeVersion, includeUpdated, includeNil,
|
||||
|
|
@ -122,7 +122,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
|||
}
|
||||
}
|
||||
|
||||
var val interface{}
|
||||
var val any
|
||||
|
||||
if fieldValue.CanAddr() {
|
||||
if structConvert, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
|
||||
|
|
@ -424,9 +424,9 @@ func (statement *Statement) writeUpdateLimit(updateWriter *builder.BytesWriter,
|
|||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) GenConditionsFromMap(m interface{}) ([]builder.Cond, error) {
|
||||
func (statement *Statement) GenConditionsFromMap(m any) ([]builder.Cond, error) {
|
||||
switch t := m.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
conds := []builder.Cond{}
|
||||
for k, v := range t {
|
||||
conds = append(conds, builder.Eq{k: v})
|
||||
|
|
@ -541,7 +541,7 @@ func (statement *Statement) writeExprSets(w *builder.BytesWriter, hasPreviousSet
|
|||
return nil
|
||||
}
|
||||
|
||||
func (statement *Statement) writeSetColumns(colNames []string, args []interface{}) func(w *builder.BytesWriter) error {
|
||||
func (statement *Statement) writeSetColumns(colNames []string, args []any) func(w *builder.BytesWriter) error {
|
||||
return func(w *builder.BytesWriter) error {
|
||||
if len(colNames) == 0 {
|
||||
return nil
|
||||
|
|
@ -564,7 +564,13 @@ func (statement *Statement) writeSetColumns(colNames []string, args []interface{
|
|||
}
|
||||
}
|
||||
|
||||
func (statement *Statement) writeUpdateSets(w *builder.BytesWriter, v reflect.Value, colNames []string, args []interface{}) error {
|
||||
func (statement *Statement) writeUpdateSets(w *builder.BytesWriter, v reflect.Value, colNames []string, args []any) error {
|
||||
// write set
|
||||
if _, err := fmt.Fprint(w, " SET "); err != nil {
|
||||
return err
|
||||
}
|
||||
previousLen := w.Len()
|
||||
|
||||
if err := statement.writeSetColumns(colNames, args)(w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -588,12 +594,17 @@ func (statement *Statement) writeUpdateSets(w *builder.BytesWriter, v reflect.Va
|
|||
if err := statement.writeVersionIncrSet(w, v, setNumber > 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if no columns to be updated, return error
|
||||
if previousLen == w.Len() {
|
||||
return ErrNoColumnsTobeUpdated
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var ErrNoColumnsTobeUpdated = errors.New("no columns found to be updated")
|
||||
|
||||
func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []interface{}) error {
|
||||
func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []any) error {
|
||||
if _, err := fmt.Fprintf(updateWriter, "UPDATE"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -606,21 +617,10 @@ func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond
|
|||
return err
|
||||
}
|
||||
|
||||
// write set
|
||||
if _, err := fmt.Fprint(updateWriter, " SET "); err != nil {
|
||||
return err
|
||||
}
|
||||
previousLen := updateWriter.Len()
|
||||
|
||||
if err := statement.writeUpdateSets(updateWriter, v, colNames, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if no columns to be updated, return error
|
||||
if previousLen == updateWriter.Len() {
|
||||
return ErrNoColumnsTobeUpdated
|
||||
}
|
||||
|
||||
// write from
|
||||
if err := statement.writeUpdateFrom(updateWriter); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ var (
|
|||
)
|
||||
|
||||
// Value2Interface convert a field value of a struct to interface for putting into database
|
||||
func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue reflect.Value) (interface{}, error) {
|
||||
func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue reflect.Value) (any, error) {
|
||||
if fieldValue.CanAddr() {
|
||||
if fieldConvert, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
|
||||
data, err := fieldConvert.ToDB()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
type BuildReader interface {
|
||||
String() string
|
||||
Args() []interface{}
|
||||
Args() []any
|
||||
}
|
||||
|
||||
// WriteBuilder writes writers to one
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ import (
|
|||
)
|
||||
|
||||
// ReflectValue returns value of a bean
|
||||
func ReflectValue(bean interface{}) reflect.Value {
|
||||
func ReflectValue(bean any) reflect.Value {
|
||||
return reflect.Indirect(reflect.ValueOf(bean))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ type Zeroable interface {
|
|||
var nilTime *time.Time
|
||||
|
||||
// IsZero returns false if k is nil or has a zero value
|
||||
func IsZero(k interface{}) bool {
|
||||
func IsZero(k any) bool {
|
||||
if k == nil {
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type MyInt int
|
||||
type ZeroStruct struct{}
|
||||
type (
|
||||
MyInt int
|
||||
ZeroStruct struct{}
|
||||
)
|
||||
|
||||
func TestZero(t *testing.T) {
|
||||
var zeroValues = []interface{}{
|
||||
zeroValues := []any{
|
||||
int8(0),
|
||||
int16(0),
|
||||
int(0),
|
||||
|
|
@ -46,7 +48,7 @@ func TestZero(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsValueZero(t *testing.T) {
|
||||
var zeroReflectValues = []reflect.Value{
|
||||
zeroReflectValues := []reflect.Value{
|
||||
reflect.ValueOf(int8(0)),
|
||||
reflect.ValueOf(int16(0)),
|
||||
reflect.ValueOf(int(0)),
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@ import (
|
|||
)
|
||||
|
||||
// IterFunc only use by Iterate
|
||||
type IterFunc func(idx int, bean interface{}) error
|
||||
type IterFunc func(idx int, bean any) error
|
||||
|
||||
// Rows return sql.Rows compatible Rows obj, as a forward Iterator object for iterating record by record, bean's non-empty fields
|
||||
// are conditions.
|
||||
func (session *Session) Rows(bean interface{}) (*Rows, error) {
|
||||
func (session *Session) Rows(bean any) (*Rows, error) {
|
||||
return newRows(session, bean)
|
||||
}
|
||||
|
||||
// Iterate record by record handle records from table, condiBeans's non-empty fields
|
||||
// are conditions. beans could be []Struct, []*Struct, map[int64]Struct
|
||||
// map[int64]*Struct
|
||||
func (session *Session) Iterate(bean interface{}, fun IterFunc) error {
|
||||
func (session *Session) Iterate(bean any, fun IterFunc) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ func (session *Session) BufferSize(size int) *Session {
|
|||
return session
|
||||
}
|
||||
|
||||
func (session *Session) bufferIterate(bean interface{}, fun IterFunc) error {
|
||||
func (session *Session) bufferIterate(bean any, fun IterFunc) error {
|
||||
bufferSize := session.statement.BufferSize
|
||||
pLimitN := session.statement.LimitN
|
||||
if pLimitN != nil && bufferSize > *pLimitN {
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@ const (
|
|||
|
||||
// Logger is a logger interface
|
||||
type Logger interface {
|
||||
Debug(v ...interface{})
|
||||
Debugf(format string, v ...interface{})
|
||||
Error(v ...interface{})
|
||||
Errorf(format string, v ...interface{})
|
||||
Info(v ...interface{})
|
||||
Infof(format string, v ...interface{})
|
||||
Warn(v ...interface{})
|
||||
Warnf(format string, v ...interface{})
|
||||
Debug(v ...any)
|
||||
Debugf(format string, v ...any)
|
||||
Error(v ...any)
|
||||
Errorf(format string, v ...any)
|
||||
Info(v ...any)
|
||||
Infof(format string, v ...any)
|
||||
Warn(v ...any)
|
||||
Warnf(format string, v ...any)
|
||||
|
||||
Level() LogLevel
|
||||
SetLevel(l LogLevel)
|
||||
|
|
@ -55,28 +55,28 @@ var _ Logger = DiscardLogger{}
|
|||
type DiscardLogger struct{}
|
||||
|
||||
// Debug empty implementation
|
||||
func (DiscardLogger) Debug(v ...interface{}) {}
|
||||
func (DiscardLogger) Debug(v ...any) {}
|
||||
|
||||
// Debugf empty implementation
|
||||
func (DiscardLogger) Debugf(format string, v ...interface{}) {}
|
||||
func (DiscardLogger) Debugf(format string, v ...any) {}
|
||||
|
||||
// Error empty implementation
|
||||
func (DiscardLogger) Error(v ...interface{}) {}
|
||||
func (DiscardLogger) Error(v ...any) {}
|
||||
|
||||
// Errorf empty implementation
|
||||
func (DiscardLogger) Errorf(format string, v ...interface{}) {}
|
||||
func (DiscardLogger) Errorf(format string, v ...any) {}
|
||||
|
||||
// Info empty implementation
|
||||
func (DiscardLogger) Info(v ...interface{}) {}
|
||||
func (DiscardLogger) Info(v ...any) {}
|
||||
|
||||
// Infof empty implementation
|
||||
func (DiscardLogger) Infof(format string, v ...interface{}) {}
|
||||
func (DiscardLogger) Infof(format string, v ...any) {}
|
||||
|
||||
// Warn empty implementation
|
||||
func (DiscardLogger) Warn(v ...interface{}) {}
|
||||
func (DiscardLogger) Warn(v ...any) {}
|
||||
|
||||
// Warnf empty implementation
|
||||
func (DiscardLogger) Warnf(format string, v ...interface{}) {}
|
||||
func (DiscardLogger) Warnf(format string, v ...any) {}
|
||||
|
||||
// Level empty implementation
|
||||
func (DiscardLogger) Level() LogLevel {
|
||||
|
|
@ -128,56 +128,56 @@ func NewSimpleLogger3(out io.Writer, prefix string, flag int, l LogLevel) *Simpl
|
|||
}
|
||||
|
||||
// Error implement ILogger
|
||||
func (s *SimpleLogger) Error(v ...interface{}) {
|
||||
func (s *SimpleLogger) Error(v ...any) {
|
||||
if s.level <= LOG_ERR {
|
||||
_ = s.ERR.Output(2, fmt.Sprintln(v...))
|
||||
}
|
||||
}
|
||||
|
||||
// Errorf implement ILogger
|
||||
func (s *SimpleLogger) Errorf(format string, v ...interface{}) {
|
||||
func (s *SimpleLogger) Errorf(format string, v ...any) {
|
||||
if s.level <= LOG_ERR {
|
||||
_ = s.ERR.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
}
|
||||
|
||||
// Debug implement ILogger
|
||||
func (s *SimpleLogger) Debug(v ...interface{}) {
|
||||
func (s *SimpleLogger) Debug(v ...any) {
|
||||
if s.level <= LOG_DEBUG {
|
||||
_ = s.DEBUG.Output(2, fmt.Sprintln(v...))
|
||||
}
|
||||
}
|
||||
|
||||
// Debugf implement ILogger
|
||||
func (s *SimpleLogger) Debugf(format string, v ...interface{}) {
|
||||
func (s *SimpleLogger) Debugf(format string, v ...any) {
|
||||
if s.level <= LOG_DEBUG {
|
||||
_ = s.DEBUG.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
}
|
||||
|
||||
// Info implement ILogger
|
||||
func (s *SimpleLogger) Info(v ...interface{}) {
|
||||
func (s *SimpleLogger) Info(v ...any) {
|
||||
if s.level <= LOG_INFO {
|
||||
_ = s.INFO.Output(2, fmt.Sprintln(v...))
|
||||
}
|
||||
}
|
||||
|
||||
// Infof implement ILogger
|
||||
func (s *SimpleLogger) Infof(format string, v ...interface{}) {
|
||||
func (s *SimpleLogger) Infof(format string, v ...any) {
|
||||
if s.level <= LOG_INFO {
|
||||
_ = s.INFO.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
}
|
||||
|
||||
// Warn implement ILogger
|
||||
func (s *SimpleLogger) Warn(v ...interface{}) {
|
||||
func (s *SimpleLogger) Warn(v ...any) {
|
||||
if s.level <= LOG_WARNING {
|
||||
_ = s.WARN.Output(2, fmt.Sprintln(v...))
|
||||
}
|
||||
}
|
||||
|
||||
// Warnf implement ILogger
|
||||
func (s *SimpleLogger) Warnf(format string, v ...interface{}) {
|
||||
func (s *SimpleLogger) Warnf(format string, v ...any) {
|
||||
if s.level <= LOG_WARNING {
|
||||
_ = s.WARN.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ type SQLLogger interface {
|
|||
type ContextLogger interface {
|
||||
SQLLogger
|
||||
|
||||
Debugf(format string, v ...interface{})
|
||||
Errorf(format string, v ...interface{})
|
||||
Infof(format string, v ...interface{})
|
||||
Warnf(format string, v ...interface{})
|
||||
Debugf(format string, v ...any)
|
||||
Errorf(format string, v ...any)
|
||||
Infof(format string, v ...any)
|
||||
Warnf(format string, v ...any)
|
||||
|
||||
Level() LogLevel
|
||||
SetLevel(l LogLevel)
|
||||
|
|
@ -74,22 +74,22 @@ func (l *LoggerAdapter) AfterSQL(ctx LogContext) {
|
|||
}
|
||||
|
||||
// Debugf implements ContextLogger
|
||||
func (l *LoggerAdapter) Debugf(format string, v ...interface{}) {
|
||||
func (l *LoggerAdapter) Debugf(format string, v ...any) {
|
||||
l.logger.Debugf(format, v...)
|
||||
}
|
||||
|
||||
// Errorf implements ContextLogger
|
||||
func (l *LoggerAdapter) Errorf(format string, v ...interface{}) {
|
||||
func (l *LoggerAdapter) Errorf(format string, v ...any) {
|
||||
l.logger.Errorf(format, v...)
|
||||
}
|
||||
|
||||
// Infof implements ContextLogger
|
||||
func (l *LoggerAdapter) Infof(format string, v ...interface{}) {
|
||||
func (l *LoggerAdapter) Infof(format string, v ...any) {
|
||||
l.logger.Infof(format, v...)
|
||||
}
|
||||
|
||||
// Warnf implements ContextLogger
|
||||
func (l *LoggerAdapter) Warnf(format string, v ...interface{}) {
|
||||
func (l *LoggerAdapter) Warnf(format string, v ...any) {
|
||||
l.logger.Warnf(format, v...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,42 +26,42 @@ func NewSyslogLogger(w *syslog.Writer) *SyslogLogger {
|
|||
}
|
||||
|
||||
// Debug log content as Debug
|
||||
func (s *SyslogLogger) Debug(v ...interface{}) {
|
||||
func (s *SyslogLogger) Debug(v ...any) {
|
||||
_ = s.w.Debug(fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
// Debugf log content as Debug and format
|
||||
func (s *SyslogLogger) Debugf(format string, v ...interface{}) {
|
||||
func (s *SyslogLogger) Debugf(format string, v ...any) {
|
||||
_ = s.w.Debug(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Error log content as Error
|
||||
func (s *SyslogLogger) Error(v ...interface{}) {
|
||||
func (s *SyslogLogger) Error(v ...any) {
|
||||
_ = s.w.Err(fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
// Errorf log content as Errorf and format
|
||||
func (s *SyslogLogger) Errorf(format string, v ...interface{}) {
|
||||
func (s *SyslogLogger) Errorf(format string, v ...any) {
|
||||
_ = s.w.Err(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Info log content as Info
|
||||
func (s *SyslogLogger) Info(v ...interface{}) {
|
||||
func (s *SyslogLogger) Info(v ...any) {
|
||||
_ = s.w.Info(fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
// Infof log content as Infof and format
|
||||
func (s *SyslogLogger) Infof(format string, v ...interface{}) {
|
||||
func (s *SyslogLogger) Infof(format string, v ...any) {
|
||||
_ = s.w.Info(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Warn log content as Warn
|
||||
func (s *SyslogLogger) Warn(v ...interface{}) {
|
||||
func (s *SyslogLogger) Warn(v ...any) {
|
||||
_ = s.w.Warning(fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
// Warnf log content as Warnf and format
|
||||
func (s *SyslogLogger) Warnf(format string, v ...interface{}) {
|
||||
func (s *SyslogLogger) Warnf(format string, v ...any) {
|
||||
_ = s.w.Warning(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ type AfterLoadSessionProcessor interface {
|
|||
AfterLoad(*Session)
|
||||
}
|
||||
|
||||
type executedProcessorFunc func(*Session, interface{}) error
|
||||
type executedProcessorFunc func(*Session, any) error
|
||||
|
||||
type executedProcessor struct {
|
||||
fun executedProcessorFunc
|
||||
session *Session
|
||||
bean interface{}
|
||||
bean any
|
||||
}
|
||||
|
||||
func (executor *executedProcessor) execute() error {
|
||||
|
|
@ -77,13 +77,13 @@ func (session *Session) executeProcessors() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func cleanupProcessorsClosures(slices *[]func(interface{})) {
|
||||
func cleanupProcessorsClosures(slices *[]func(any)) {
|
||||
if len(*slices) > 0 {
|
||||
*slices = make([]func(interface{}), 0)
|
||||
*slices = make([]func(any), 0)
|
||||
}
|
||||
}
|
||||
|
||||
func executeBeforeClosures(session *Session, bean interface{}) {
|
||||
func executeBeforeClosures(session *Session, bean any) {
|
||||
// handle before delete processors
|
||||
for _, closure := range session.beforeClosures {
|
||||
closure(bean)
|
||||
|
|
@ -91,27 +91,27 @@ func executeBeforeClosures(session *Session, bean interface{}) {
|
|||
cleanupProcessorsClosures(&session.beforeClosures)
|
||||
}
|
||||
|
||||
func executeBeforeSet(bean interface{}, fields []string, scanResults []interface{}) {
|
||||
func executeBeforeSet(bean any, fields []string, scanResults []any) {
|
||||
if b, hasBeforeSet := bean.(BeforeSetProcessor); hasBeforeSet {
|
||||
for ii, key := range fields {
|
||||
b.BeforeSet(key, Cell(scanResults[ii].(*interface{})))
|
||||
b.BeforeSet(key, Cell(scanResults[ii].(*any)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func executeAfterSet(bean interface{}, fields []string, scanResults []interface{}) {
|
||||
func executeAfterSet(bean any, fields []string, scanResults []any) {
|
||||
if b, hasAfterSet := bean.(AfterSetProcessor); hasAfterSet {
|
||||
for ii, key := range fields {
|
||||
b.AfterSet(key, Cell(scanResults[ii].(*interface{})))
|
||||
b.AfterSet(key, Cell(scanResults[ii].(*any)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func buildAfterProcessors(session *Session, bean interface{}) {
|
||||
func buildAfterProcessors(session *Session, bean any) {
|
||||
// handle afterClosures
|
||||
for _, closure := range session.afterClosures {
|
||||
session.afterProcessors = append(session.afterProcessors, executedProcessor{
|
||||
fun: func(sess *Session, bean interface{}) error {
|
||||
fun: func(sess *Session, bean any) error {
|
||||
closure(bean)
|
||||
return nil
|
||||
},
|
||||
|
|
@ -122,7 +122,7 @@ func buildAfterProcessors(session *Session, bean interface{}) {
|
|||
|
||||
if a, has := bean.(AfterLoadProcessor); has {
|
||||
session.afterProcessors = append(session.afterProcessors, executedProcessor{
|
||||
fun: func(sess *Session, bean interface{}) error {
|
||||
fun: func(sess *Session, bean any) error {
|
||||
a.AfterLoad()
|
||||
return nil
|
||||
},
|
||||
|
|
@ -133,7 +133,7 @@ func buildAfterProcessors(session *Session, bean interface{}) {
|
|||
|
||||
if a, has := bean.(AfterLoadSessionProcessor); has {
|
||||
session.afterProcessors = append(session.afterProcessors, executedProcessor{
|
||||
fun: func(sess *Session, bean interface{}) error {
|
||||
fun: func(sess *Session, bean any) error {
|
||||
a.AfterLoad(sess)
|
||||
return nil
|
||||
},
|
||||
|
|
|
|||
20
raw.go
20
raw.go
|
|
@ -11,7 +11,7 @@ import (
|
|||
"xorm.io/xorm/v2/internal/core"
|
||||
)
|
||||
|
||||
func (session *Session) queryPreprocess(sqlStr *string, paramStr ...interface{}) {
|
||||
func (session *Session) queryPreprocess(sqlStr *string, paramStr ...any) {
|
||||
for _, filter := range session.engine.dialect.Filters() {
|
||||
*sqlStr = filter.Do(session.ctx, *sqlStr)
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ func (session *Session) queryPreprocess(sqlStr *string, paramStr ...interface{})
|
|||
session.lastSQLArgs = paramStr
|
||||
}
|
||||
|
||||
func (session *Session) queryRows(sqlStr string, args ...interface{}) (*core.Rows, error) {
|
||||
func (session *Session) queryRows(sqlStr string, args ...any) (*core.Rows, error) {
|
||||
defer session.resetStatement()
|
||||
if session.statement.LastError != nil {
|
||||
return nil, session.statement.LastError
|
||||
|
|
@ -64,12 +64,12 @@ func (session *Session) queryRows(sqlStr string, args ...interface{}) (*core.Row
|
|||
return session.tx.QueryContext(session.ctx, sqlStr, args...)
|
||||
}
|
||||
|
||||
func (session *Session) queryRow(sqlStr string, args ...interface{}) *core.Row {
|
||||
func (session *Session) queryRow(sqlStr string, args ...any) *core.Row {
|
||||
return core.NewRow(session.queryRows(sqlStr, args...))
|
||||
}
|
||||
|
||||
// Query runs a raw sql and return records as []map[string][]byte
|
||||
func (session *Session) Query(sqlOrArgs ...interface{}) ([]map[string][]byte, error) {
|
||||
func (session *Session) Query(sqlOrArgs ...any) ([]map[string][]byte, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ func (session *Session) Query(sqlOrArgs ...interface{}) ([]map[string][]byte, er
|
|||
}
|
||||
|
||||
// QueryString runs a raw sql and return records as []map[string]string
|
||||
func (session *Session) QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error) {
|
||||
func (session *Session) QueryString(sqlOrArgs ...any) ([]map[string]string, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ func (session *Session) QueryString(sqlOrArgs ...interface{}) ([]map[string]stri
|
|||
}
|
||||
|
||||
// QuerySliceString runs a raw sql and return records as [][]string
|
||||
func (session *Session) QuerySliceString(sqlOrArgs ...interface{}) ([][]string, error) {
|
||||
func (session *Session) QuerySliceString(sqlOrArgs ...any) ([][]string, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -128,8 +128,8 @@ func (session *Session) QuerySliceString(sqlOrArgs ...interface{}) ([][]string,
|
|||
return session.engine.ScanStringSlices(rows)
|
||||
}
|
||||
|
||||
// QueryInterface runs a raw sql and return records as []map[string]interface{}
|
||||
func (session *Session) QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error) {
|
||||
// QueryInterface runs a raw sql and return records as []map[string]any
|
||||
func (session *Session) QueryInterface(sqlOrArgs ...any) ([]map[string]any, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ func (session *Session) QueryInterface(sqlOrArgs ...interface{}) ([]map[string]i
|
|||
return session.engine.ScanInterfaceMaps(rows)
|
||||
}
|
||||
|
||||
func (session *Session) exec(sqlStr string, args ...interface{}) (sql.Result, error) {
|
||||
func (session *Session) exec(sqlStr string, args ...any) (sql.Result, error) {
|
||||
defer session.resetStatement()
|
||||
|
||||
session.queryPreprocess(&sqlStr, args...)
|
||||
|
|
@ -179,7 +179,7 @@ func (session *Session) exec(sqlStr string, args ...interface{}) (sql.Result, er
|
|||
}
|
||||
|
||||
// Exec raw sql
|
||||
func (session *Session) Exec(sqlOrArgs ...interface{}) (sql.Result, error) {
|
||||
func (session *Session) Exec(sqlOrArgs ...any) (sql.Result, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
|
|||
6
rows.go
6
rows.go
|
|
@ -20,13 +20,13 @@ type Rows struct {
|
|||
beanType reflect.Type
|
||||
}
|
||||
|
||||
func newRows(session *Session, bean interface{}) (*Rows, error) {
|
||||
func newRows(session *Session, bean any) (*Rows, error) {
|
||||
rows := new(Rows)
|
||||
rows.session = session
|
||||
rows.beanType = reflect.Indirect(reflect.ValueOf(bean)).Type()
|
||||
|
||||
var sqlStr string
|
||||
var args []interface{}
|
||||
var args []any
|
||||
var err error
|
||||
|
||||
beanValue := reflect.ValueOf(bean)
|
||||
|
|
@ -98,7 +98,7 @@ func (rows *Rows) Err() error {
|
|||
}
|
||||
|
||||
// Scan row record to bean properties
|
||||
func (rows *Rows) Scan(beans ...interface{}) error {
|
||||
func (rows *Rows) Scan(beans ...any) error {
|
||||
if rows.Err() != nil {
|
||||
return rows.Err()
|
||||
}
|
||||
|
|
|
|||
36
scan.go
36
scan.go
|
|
@ -18,9 +18,9 @@ import (
|
|||
)
|
||||
|
||||
// genScanResultsByBeanNullabale generates scan result
|
||||
func genScanResultsByBeanNullable(bean interface{}) (interface{}, bool, error) {
|
||||
func genScanResultsByBeanNullable(bean any) (any, bool, error) {
|
||||
switch t := bean.(type) {
|
||||
case *interface{}:
|
||||
case *any:
|
||||
return t, false, nil
|
||||
case *sql.NullInt64, *sql.NullBool, *sql.NullFloat64, *sql.NullString, *sql.RawBytes, *[]byte:
|
||||
return t, false, nil
|
||||
|
|
@ -71,9 +71,9 @@ func genScanResultsByBeanNullable(bean interface{}) (interface{}, bool, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func genScanResultsByBean(bean interface{}) (interface{}, bool, error) {
|
||||
func genScanResultsByBean(bean any) (any, bool, error) {
|
||||
switch t := bean.(type) {
|
||||
case *interface{}:
|
||||
case *any:
|
||||
return t, false, nil
|
||||
case *sql.NullInt64, *sql.NullBool, *sql.NullFloat64, *sql.NullString,
|
||||
*sql.RawBytes,
|
||||
|
|
@ -129,8 +129,8 @@ func genScanResultsByBean(bean interface{}) (interface{}, bool, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (engine *Engine) scanStringInterface(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]interface{}, error) {
|
||||
scanResults := make([]interface{}, len(types))
|
||||
func (engine *Engine) scanStringInterface(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]any, error) {
|
||||
scanResults := make([]any, len(types))
|
||||
for i := 0; i < len(types); i++ {
|
||||
var s sql.NullString
|
||||
scanResults[i] = &s
|
||||
|
|
@ -143,13 +143,13 @@ func (engine *Engine) scanStringInterface(rows *core.Rows, fields []string, type
|
|||
}
|
||||
|
||||
// scan is a wrap of driver.Scan but will automatically change the input values according requirements
|
||||
func (engine *Engine) scan(rows *core.Rows, fields []string, types []*sql.ColumnType, vv ...interface{}) error {
|
||||
scanResults := make([]interface{}, 0, len(types))
|
||||
func (engine *Engine) scan(rows *core.Rows, fields []string, types []*sql.ColumnType, vv ...any) error {
|
||||
scanResults := make([]any, 0, len(types))
|
||||
replaces := make([]bool, 0, len(types))
|
||||
var err error
|
||||
for _, v := range vv {
|
||||
var replaced bool
|
||||
var scanResult interface{}
|
||||
var scanResult any
|
||||
switch t := v.(type) {
|
||||
case *big.Float, *time.Time, *sql.NullTime:
|
||||
scanResult = &sql.NullString{}
|
||||
|
|
@ -193,8 +193,8 @@ func (engine *Engine) scan(rows *core.Rows, fields []string, types []*sql.Column
|
|||
return nil
|
||||
}
|
||||
|
||||
func (engine *Engine) scanInterfaces(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]interface{}, error) {
|
||||
scanResultContainers := make([]interface{}, len(types))
|
||||
func (engine *Engine) scanInterfaces(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]any, error) {
|
||||
scanResultContainers := make([]any, len(types))
|
||||
for i := 0; i < len(types); i++ {
|
||||
scanResult, err := engine.driver.GenScanResult(types[i].DatabaseTypeName())
|
||||
if err != nil {
|
||||
|
|
@ -209,11 +209,11 @@ func (engine *Engine) scanInterfaces(rows *core.Rows, fields []string, types []*
|
|||
}
|
||||
|
||||
////////////////////
|
||||
// row -> map[string]interface{}
|
||||
// row -> map[string]any
|
||||
|
||||
func (engine *Engine) row2mapInterface(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]interface{}, error) {
|
||||
resultsMap := make(map[string]interface{}, len(fields))
|
||||
scanResultContainers := make([]interface{}, len(fields))
|
||||
func (engine *Engine) row2mapInterface(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]any, error) {
|
||||
resultsMap := make(map[string]any, len(fields))
|
||||
scanResultContainers := make([]any, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
scanResult, err := engine.driver.GenScanResult(types[i].DatabaseTypeName())
|
||||
if err != nil {
|
||||
|
|
@ -236,7 +236,7 @@ func (engine *Engine) row2mapInterface(rows *core.Rows, types []*sql.ColumnType,
|
|||
}
|
||||
|
||||
// ScanInterfaceMap scan result from *core.Rows and return a map
|
||||
func (engine *Engine) ScanInterfaceMap(rows *core.Rows) (map[string]interface{}, error) {
|
||||
func (engine *Engine) ScanInterfaceMap(rows *core.Rows) (map[string]any, error) {
|
||||
fields, err := rows.Columns()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -250,7 +250,7 @@ func (engine *Engine) ScanInterfaceMap(rows *core.Rows) (map[string]interface{},
|
|||
}
|
||||
|
||||
// ScanInterfaceMaps scan results from *core.Rows and return a slice of map
|
||||
func (engine *Engine) ScanInterfaceMaps(rows *core.Rows) (resultsSlice []map[string]interface{}, err error) {
|
||||
func (engine *Engine) ScanInterfaceMaps(rows *core.Rows) (resultsSlice []map[string]any, err error) {
|
||||
fields, err := rows.Columns()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -277,7 +277,7 @@ func (engine *Engine) ScanInterfaceMaps(rows *core.Rows) (resultsSlice []map[str
|
|||
// row -> map[string]string
|
||||
|
||||
func (engine *Engine) row2mapStr(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]string, error) {
|
||||
scanResults := make([]interface{}, len(fields))
|
||||
scanResults := make([]any, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
var s sql.NullString
|
||||
scanResults[i] = &s
|
||||
|
|
|
|||
28
schema.go
28
schema.go
|
|
@ -28,7 +28,7 @@ func (session *Session) Ping() error {
|
|||
}
|
||||
|
||||
// CreateTable create a table according a bean
|
||||
func (session *Session) CreateTable(bean interface{}) error {
|
||||
func (session *Session) CreateTable(bean any) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ func (session *Session) CreateTable(bean interface{}) error {
|
|||
return session.createTable(bean)
|
||||
}
|
||||
|
||||
func (session *Session) createTable(bean interface{}) error {
|
||||
func (session *Session) createTable(bean any) error {
|
||||
if err := session.statement.SetRefBean(bean); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ func (session *Session) createTable(bean interface{}) error {
|
|||
}
|
||||
|
||||
// CreateIndexes create indexes
|
||||
func (session *Session) CreateIndexes(bean interface{}) error {
|
||||
func (session *Session) CreateIndexes(bean any) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ func (session *Session) CreateIndexes(bean interface{}) error {
|
|||
return session.createIndexes(bean)
|
||||
}
|
||||
|
||||
func (session *Session) createIndexes(bean interface{}) error {
|
||||
func (session *Session) createIndexes(bean any) error {
|
||||
if err := session.statement.SetRefBean(bean); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -91,14 +91,14 @@ func (session *Session) createIndexes(bean interface{}) error {
|
|||
}
|
||||
|
||||
// CreateUniques create uniques
|
||||
func (session *Session) CreateUniques(bean interface{}) error {
|
||||
func (session *Session) CreateUniques(bean any) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
return session.createUniques(bean)
|
||||
}
|
||||
|
||||
func (session *Session) createUniques(bean interface{}) error {
|
||||
func (session *Session) createUniques(bean any) error {
|
||||
if err := session.statement.SetRefBean(bean); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ func (session *Session) createUniques(bean interface{}) error {
|
|||
}
|
||||
|
||||
// DropIndexes drop indexes
|
||||
func (session *Session) DropIndexes(bean interface{}) error {
|
||||
func (session *Session) DropIndexes(bean any) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ func (session *Session) DropIndexes(bean interface{}) error {
|
|||
return session.dropIndexes(bean)
|
||||
}
|
||||
|
||||
func (session *Session) dropIndexes(bean interface{}) error {
|
||||
func (session *Session) dropIndexes(bean any) error {
|
||||
if err := session.statement.SetRefBean(bean); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ func (session *Session) dropIndexes(bean interface{}) error {
|
|||
}
|
||||
|
||||
// DropTable drop table will drop table if exist, if drop failed, it will return error
|
||||
func (session *Session) DropTable(beanOrTableName interface{}) error {
|
||||
func (session *Session) DropTable(beanOrTableName any) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -146,11 +146,11 @@ func (session *Session) DropTable(beanOrTableName interface{}) error {
|
|||
return session.dropTable(beanOrTableName)
|
||||
}
|
||||
|
||||
func (session *Session) dropTable(beanOrTableName interface{}) error {
|
||||
func (session *Session) dropTable(beanOrTableName any) error {
|
||||
tableName := session.engine.TableName(beanOrTableName)
|
||||
sqlStr, checkIfExist := session.engine.dialect.DropTableSQL(session.engine.TableName(tableName, true))
|
||||
if !checkIfExist {
|
||||
exist, err := session.engine.dialect.IsTableExist(session.getQueryer(), session.ctx, tableName)
|
||||
exist, err := session.engine.dialect.IsTableExist(session.ctx, session.getQueryer(), tableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ func (session *Session) dropTable(beanOrTableName interface{}) error {
|
|||
}
|
||||
|
||||
// IsTableExist if a table is exist
|
||||
func (session *Session) IsTableExist(beanOrTableName interface{}) (bool, error) {
|
||||
func (session *Session) IsTableExist(beanOrTableName any) (bool, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -197,11 +197,11 @@ func (session *Session) IsTableExist(beanOrTableName interface{}) (bool, error)
|
|||
}
|
||||
|
||||
func (session *Session) isTableExist(tableName string) (bool, error) {
|
||||
return session.engine.dialect.IsTableExist(session.getQueryer(), session.ctx, tableName)
|
||||
return session.engine.dialect.IsTableExist(session.ctx, session.getQueryer(), tableName)
|
||||
}
|
||||
|
||||
// IsTableEmpty if table have any records
|
||||
func (session *Session) IsTableEmpty(bean interface{}) (bool, error) {
|
||||
func (session *Session) IsTableEmpty(bean any) (bool, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int64, nullab
|
|||
}
|
||||
|
||||
// ValueOf returns column's filed of struct's value
|
||||
func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error) {
|
||||
func (col *Column) ValueOf(bean any) (*reflect.Value, error) {
|
||||
dataStruct := reflect.Indirect(reflect.ValueOf(bean))
|
||||
return col.ValueOfV(&dataStruct)
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) {
|
|||
}
|
||||
|
||||
// ConvertID converts id content to suitable type according column type
|
||||
func (col *Column) ConvertID(sid string) (interface{}, error) {
|
||||
func (col *Column) ConvertID(sid string) (any, error) {
|
||||
if col.SQLType.IsNumeric() {
|
||||
n, err := strconv.ParseInt(sid, 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ import (
|
|||
)
|
||||
|
||||
// PK represents primary key values
|
||||
type PK []interface{}
|
||||
type PK []any
|
||||
|
||||
// NewPK creates primay keys
|
||||
func NewPK(pks ...interface{}) *PK {
|
||||
func NewPK(pks ...any) *PK {
|
||||
p := PK(pks)
|
||||
return &p
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ func (table *Table) AddIndex(index *Index) {
|
|||
// IDOfV get id from one value of struct
|
||||
func (table *Table) IDOfV(rv reflect.Value) (PK, error) {
|
||||
v := reflect.Indirect(rv)
|
||||
pk := make([]interface{}, len(table.PrimaryKeys))
|
||||
pk := make([]any, len(table.PrimaryKeys))
|
||||
for i, col := range table.PKColumns() {
|
||||
var err error
|
||||
|
||||
|
|
|
|||
56
session.go
56
session.go
|
|
@ -68,20 +68,20 @@ type Session struct {
|
|||
autoResetStatement bool
|
||||
|
||||
// !nashtsai! storing these beans due to yet committed tx
|
||||
afterInsertBeans map[interface{}]*[]func(interface{})
|
||||
afterUpdateBeans map[interface{}]*[]func(interface{})
|
||||
afterDeleteBeans map[interface{}]*[]func(interface{})
|
||||
afterInsertBeans map[any]*[]func(any)
|
||||
afterUpdateBeans map[any]*[]func(any)
|
||||
afterDeleteBeans map[any]*[]func(any)
|
||||
// --
|
||||
|
||||
beforeClosures []func(interface{})
|
||||
afterClosures []func(interface{})
|
||||
beforeClosures []func(any)
|
||||
afterClosures []func(any)
|
||||
afterProcessors []executedProcessor
|
||||
|
||||
stmtCache map[uint32]*core.Stmt // key: hash.Hash32 of (queryStr, len(queryStr))
|
||||
txStmtCache map[uint32]*core.Stmt // for tx statement
|
||||
|
||||
lastSQL string
|
||||
lastSQLArgs []interface{}
|
||||
lastSQLArgs []any
|
||||
|
||||
ctx context.Context
|
||||
sessionType sessionType
|
||||
|
|
@ -122,17 +122,17 @@ func newSession(engine *Engine) *Session {
|
|||
autoResetStatement: true,
|
||||
prepareStmt: false,
|
||||
|
||||
afterInsertBeans: make(map[interface{}]*[]func(interface{})),
|
||||
afterUpdateBeans: make(map[interface{}]*[]func(interface{})),
|
||||
afterDeleteBeans: make(map[interface{}]*[]func(interface{})),
|
||||
beforeClosures: make([]func(interface{}), 0),
|
||||
afterClosures: make([]func(interface{}), 0),
|
||||
afterInsertBeans: make(map[any]*[]func(any)),
|
||||
afterUpdateBeans: make(map[any]*[]func(any)),
|
||||
afterDeleteBeans: make(map[any]*[]func(any)),
|
||||
beforeClosures: make([]func(any), 0),
|
||||
afterClosures: make([]func(any), 0),
|
||||
afterProcessors: make([]executedProcessor, 0),
|
||||
stmtCache: make(map[uint32]*core.Stmt),
|
||||
txStmtCache: make(map[uint32]*core.Stmt),
|
||||
|
||||
lastSQL: "",
|
||||
lastSQLArgs: make([]interface{}, 0),
|
||||
lastSQLArgs: make([]any, 0),
|
||||
|
||||
sessionType: engineSession,
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ func (session *Session) Prepare() *Session {
|
|||
}
|
||||
|
||||
// Before Apply before Processor, affected bean is passed to closure arg
|
||||
func (session *Session) Before(closures func(interface{})) *Session {
|
||||
func (session *Session) Before(closures func(any)) *Session {
|
||||
if closures != nil {
|
||||
session.beforeClosures = append(session.beforeClosures, closures)
|
||||
}
|
||||
|
|
@ -226,7 +226,7 @@ func (session *Session) Before(closures func(interface{})) *Session {
|
|||
}
|
||||
|
||||
// After Apply after Processor, affected bean is passed to closure arg
|
||||
func (session *Session) After(closures func(interface{})) *Session {
|
||||
func (session *Session) After(closures func(any)) *Session {
|
||||
if closures != nil {
|
||||
session.afterClosures = append(session.afterClosures, closures)
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ func (session *Session) After(closures func(interface{})) *Session {
|
|||
}
|
||||
|
||||
// Table can input a string or pointer to struct for special a table to operate.
|
||||
func (session *Session) Table(tableNameOrBean interface{}) *Session {
|
||||
func (session *Session) Table(tableNameOrBean any) *Session {
|
||||
if err := session.statement.SetTable(tableNameOrBean); err != nil {
|
||||
session.statement.LastError = err
|
||||
}
|
||||
|
|
@ -273,7 +273,7 @@ func (session *Session) Limit(limit int, start ...int) *Session {
|
|||
|
||||
// OrderBy provide order by query condition, the input parameter is the content
|
||||
// after order by on a sql statement.
|
||||
func (session *Session) OrderBy(order interface{}, args ...interface{}) *Session {
|
||||
func (session *Session) OrderBy(order any, args ...any) *Session {
|
||||
session.statement.OrderBy(order, args...)
|
||||
return session
|
||||
}
|
||||
|
|
@ -321,7 +321,7 @@ func (session *Session) MustLogSQL(logs ...bool) *Session {
|
|||
}
|
||||
|
||||
// Join join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
|
||||
func (session *Session) Join(joinOperator string, tablename interface{}, condition interface{}, args ...interface{}) *Session {
|
||||
func (session *Session) Join(joinOperator string, tablename any, condition any, args ...any) *Session {
|
||||
session.statement.Join(joinOperator, tablename, condition, args...)
|
||||
return session
|
||||
}
|
||||
|
|
@ -374,7 +374,7 @@ func getField(dataStruct *reflect.Value, table *schemas.Table, field *QueryedFie
|
|||
}
|
||||
|
||||
// Cell cell is a result of one column field
|
||||
type Cell *interface{}
|
||||
type Cell *any
|
||||
|
||||
func (session *Session) rows2Beans(rows *core.Rows, columnsSchema *ColumnsSchema, fields []string, types []*sql.ColumnType,
|
||||
table *schemas.Table, newElemFunc func([]string) reflect.Value,
|
||||
|
|
@ -395,7 +395,7 @@ func (session *Session) rows2Beans(rows *core.Rows, columnsSchema *ColumnsSchema
|
|||
return err
|
||||
}
|
||||
session.afterProcessors = append(session.afterProcessors, executedProcessor{
|
||||
fun: func(*Session, interface{}) error {
|
||||
fun: func(*Session, any) error {
|
||||
return sliceValueSetFunc(&newValue, pk)
|
||||
},
|
||||
session: session,
|
||||
|
|
@ -405,14 +405,14 @@ func (session *Session) rows2Beans(rows *core.Rows, columnsSchema *ColumnsSchema
|
|||
return rows.Err()
|
||||
}
|
||||
|
||||
func (session *Session) row2Slice(rows *core.Rows, fields []string, types []*sql.ColumnType, bean interface{}) ([]interface{}, error) {
|
||||
func (session *Session) row2Slice(rows *core.Rows, fields []string, types []*sql.ColumnType, bean any) ([]any, error) {
|
||||
for _, closure := range session.beforeClosures {
|
||||
closure(bean)
|
||||
}
|
||||
|
||||
scanResults := make([]interface{}, len(fields))
|
||||
scanResults := make([]any, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
var cell interface{}
|
||||
var cell any
|
||||
scanResults[i] = &cell
|
||||
}
|
||||
if err := session.engine.scan(rows, fields, types, scanResults...); err != nil {
|
||||
|
|
@ -424,7 +424,7 @@ func (session *Session) row2Slice(rows *core.Rows, fields []string, types []*sql
|
|||
return scanResults, nil
|
||||
}
|
||||
|
||||
func setJSON(fieldValue *reflect.Value, fieldType reflect.Type, scanResult interface{}) error {
|
||||
func setJSON(fieldValue *reflect.Value, fieldType reflect.Type, scanResult any) error {
|
||||
bs, ok := convert.AsBytes(scanResult)
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported database data type: %#v", scanResult)
|
||||
|
|
@ -457,9 +457,9 @@ func setJSON(fieldValue *reflect.Value, fieldType reflect.Type, scanResult inter
|
|||
var uint8ZeroValue = reflect.ValueOf(uint8(0))
|
||||
|
||||
func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflect.Value,
|
||||
scanResult interface{}, table *schemas.Table,
|
||||
scanResult any, table *schemas.Table,
|
||||
) error {
|
||||
v, ok := scanResult.(*interface{})
|
||||
v, ok := scanResult.(*any)
|
||||
if ok {
|
||||
scanResult = *v
|
||||
}
|
||||
|
|
@ -625,7 +625,7 @@ func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflec
|
|||
return convert.AssignValue(fieldValue.Addr(), scanResult)
|
||||
}
|
||||
|
||||
func (session *Session) slice2Bean(scanResults []interface{}, columnsSchema *ColumnsSchema, fields []string, bean interface{}, dataStruct *reflect.Value, table *schemas.Table) (schemas.PK, error) {
|
||||
func (session *Session) slice2Bean(scanResults []any, columnsSchema *ColumnsSchema, fields []string, bean any, dataStruct *reflect.Value, table *schemas.Table) (schemas.PK, error) {
|
||||
defer func() {
|
||||
executeAfterSet(bean, fields, scanResults)
|
||||
}()
|
||||
|
|
@ -656,13 +656,13 @@ func (session *Session) slice2Bean(scanResults []interface{}, columnsSchema *Col
|
|||
}
|
||||
|
||||
// saveLastSQL stores executed query information
|
||||
func (session *Session) saveLastSQL(sql string, args ...interface{}) {
|
||||
func (session *Session) saveLastSQL(sql string, args ...any) {
|
||||
session.lastSQL = sql
|
||||
session.lastSQLArgs = args
|
||||
}
|
||||
|
||||
// LastSQL returns last query information
|
||||
func (session *Session) LastSQL() (string, []interface{}) {
|
||||
func (session *Session) LastSQL() (string, []any) {
|
||||
return session.lastSQL, session.lastSQLArgs
|
||||
}
|
||||
|
||||
|
|
|
|||
12
stats.go
12
stats.go
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
// Count counts the records. bean's non-empty fields
|
||||
// are conditions.
|
||||
func (session *Session) Count(bean ...interface{}) (int64, error) {
|
||||
func (session *Session) Count(bean ...any) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ func (session *Session) Count(bean ...interface{}) (int64, error) {
|
|||
}
|
||||
|
||||
// sum call sum some column. bean's non-empty fields are conditions.
|
||||
func (session *Session) sum(res interface{}, bean interface{}, columnNames ...string) error {
|
||||
func (session *Session) sum(res any, bean any, columnNames ...string) error {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -59,23 +59,23 @@ func (session *Session) sum(res interface{}, bean interface{}, columnNames ...st
|
|||
}
|
||||
|
||||
// Sum call sum some column. bean's non-empty fields are conditions.
|
||||
func (session *Session) Sum(bean interface{}, columnName string) (res float64, err error) {
|
||||
func (session *Session) Sum(bean any, columnName string) (res float64, err error) {
|
||||
return res, session.sum(&res, bean, columnName)
|
||||
}
|
||||
|
||||
// SumInt call sum some column. bean's non-empty fields are conditions.
|
||||
func (session *Session) SumInt(bean interface{}, columnName string) (res int64, err error) {
|
||||
func (session *Session) SumInt(bean any, columnName string) (res int64, err error) {
|
||||
return res, session.sum(&res, bean, columnName)
|
||||
}
|
||||
|
||||
// Sums call sum some columns. bean's non-empty fields are conditions.
|
||||
func (session *Session) Sums(bean interface{}, columnNames ...string) ([]float64, error) {
|
||||
func (session *Session) Sums(bean any, columnNames ...string) ([]float64, error) {
|
||||
res := make([]float64, len(columnNames))
|
||||
return res, session.sum(&res, bean, columnNames...)
|
||||
}
|
||||
|
||||
// SumsInt sum specify columns and return as []int64 instead of []float64
|
||||
func (session *Session) SumsInt(bean interface{}, columnNames ...string) ([]int64, error) {
|
||||
func (session *Session) SumsInt(bean any, columnNames ...string) ([]int64, error) {
|
||||
res := make([]int64, len(columnNames))
|
||||
return res, session.sum(&res, bean, columnNames...)
|
||||
}
|
||||
|
|
|
|||
14
sync.go
14
sync.go
|
|
@ -24,14 +24,14 @@ type SyncResult struct{}
|
|||
// Sync the new struct changes to database, this method will automatically add
|
||||
// table, column, index, unique. but will not delete or change anything.
|
||||
// If you change some field, you should change the database manually.
|
||||
func (engine *Engine) Sync(beans ...interface{}) error {
|
||||
func (engine *Engine) Sync(beans ...any) error {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Sync(beans...)
|
||||
}
|
||||
|
||||
// SyncWithOptions sync the database schemas according options and table structs
|
||||
func (engine *Engine) SyncWithOptions(opts SyncOptions, beans ...interface{}) (*SyncResult, error) {
|
||||
func (engine *Engine) SyncWithOptions(opts SyncOptions, beans ...any) (*SyncResult, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.SyncWithOptions(opts, beans...)
|
||||
|
|
@ -39,18 +39,18 @@ func (engine *Engine) SyncWithOptions(opts SyncOptions, beans ...interface{}) (*
|
|||
|
||||
// Sync2 synchronize structs to database tables
|
||||
// Depricated
|
||||
func (engine *Engine) Sync2(beans ...interface{}) error {
|
||||
func (engine *Engine) Sync2(beans ...any) error {
|
||||
return engine.Sync(beans...)
|
||||
}
|
||||
|
||||
// Sync2 synchronize structs to database tables
|
||||
// Depricated
|
||||
func (session *Session) Sync2(beans ...interface{}) error {
|
||||
func (session *Session) Sync2(beans ...any) error {
|
||||
return session.Sync(beans...)
|
||||
}
|
||||
|
||||
// Sync synchronize structs to database tables
|
||||
func (session *Session) Sync(beans ...interface{}) error {
|
||||
func (session *Session) Sync(beans ...any) error {
|
||||
_, err := session.SyncWithOptions(SyncOptions{
|
||||
WarnIfDatabaseColumnMissed: false,
|
||||
IgnoreConstrains: false,
|
||||
|
|
@ -59,7 +59,7 @@ func (session *Session) Sync(beans ...interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{}) (*SyncResult, error) {
|
||||
func (session *Session) SyncWithOptions(opts SyncOptions, beans ...any) (*SyncResult, error) {
|
||||
engine := session.engine
|
||||
|
||||
if session.isAutoClose {
|
||||
|
|
@ -67,7 +67,7 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
|||
defer session.Close()
|
||||
}
|
||||
|
||||
tables, err := engine.dialect.GetTables(session.getQueryer(), session.ctx)
|
||||
tables, err := engine.dialect.GetTables(session.ctx, session.getQueryer())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func TestAutoTransaction(t *testing.T) {
|
|||
engine := testEngine.(*xorm.Engine)
|
||||
|
||||
// will success
|
||||
_, err := engine.Transaction(func(session *xorm.Session) (interface{}, error) {
|
||||
_, err := engine.Transaction(func(session *xorm.Session) (any, error) {
|
||||
_, err := session.Insert(TestTx{Msg: "hi"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ func TestAutoTransaction(t *testing.T) {
|
|||
assert.EqualValues(t, true, has)
|
||||
|
||||
// will rollback
|
||||
_, err = engine.Transaction(func(session *xorm.Session) (interface{}, error) {
|
||||
_, err = engine.Transaction(func(session *xorm.Session) (any, error) {
|
||||
_, err := session.Insert(TestTx{Msg: "hello"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ func TestAutoTransaction(t *testing.T) {
|
|||
assert.EqualValues(t, false, has)
|
||||
}
|
||||
|
||||
func assertSync(t *testing.T, beans ...interface{}) {
|
||||
func assertSync(t *testing.T, beans ...any) {
|
||||
for _, bean := range beans {
|
||||
t.Run(testEngine.TableName(bean, true), func(t *testing.T) {
|
||||
assert.NoError(t, testEngine.DropTables(bean))
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func TestBefore_Get(t *testing.T) {
|
|||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var be BeforeTable
|
||||
has, err := testEngine.Before(func(bean interface{}) {
|
||||
has, err := testEngine.Before(func(bean any) {
|
||||
bean.(*BeforeTable).Val = "val"
|
||||
}).Get(&be)
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -60,7 +60,7 @@ func TestBefore_Find(t *testing.T) {
|
|||
assert.EqualValues(t, 2, cnt)
|
||||
|
||||
var be []BeforeTable2
|
||||
err = testEngine.Before(func(bean interface{}) {
|
||||
err = testEngine.Before(func(bean any) {
|
||||
bean.(*BeforeTable2).Val = "val"
|
||||
}).Find(&be)
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -133,7 +133,7 @@ func TestProcessors(t *testing.T) {
|
|||
err = testEngine.CreateTables(&ProcessorsStruct{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
b4InsertFunc := func(bean interface{}) {
|
||||
b4InsertFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.B4InsertViaExt = 1
|
||||
} else {
|
||||
|
|
@ -141,7 +141,7 @@ func TestProcessors(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
afterInsertFunc := func(bean interface{}) {
|
||||
afterInsertFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.AfterInsertedViaExt = 1
|
||||
} else {
|
||||
|
|
@ -234,7 +234,7 @@ func TestProcessors(t *testing.T) {
|
|||
// --
|
||||
|
||||
// test update processors
|
||||
b4UpdateFunc := func(bean interface{}) {
|
||||
b4UpdateFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.B4UpdateViaExt = 1
|
||||
} else {
|
||||
|
|
@ -242,7 +242,7 @@ func TestProcessors(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
afterUpdateFunc := func(bean interface{}) {
|
||||
afterUpdateFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.AfterUpdatedViaExt = 1
|
||||
} else {
|
||||
|
|
@ -274,7 +274,7 @@ func TestProcessors(t *testing.T) {
|
|||
// --
|
||||
|
||||
// test delete processors
|
||||
b4DeleteFunc := func(bean interface{}) {
|
||||
b4DeleteFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.B4DeleteViaExt = 1
|
||||
} else {
|
||||
|
|
@ -282,7 +282,7 @@ func TestProcessors(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
afterDeleteFunc := func(bean interface{}) {
|
||||
afterDeleteFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.AfterDeletedViaExt = 1
|
||||
} else {
|
||||
|
|
@ -374,7 +374,7 @@ func TestProcessorsTx(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
p := &ProcessorsStruct{}
|
||||
b4InsertFunc := func(bean interface{}) {
|
||||
b4InsertFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.B4InsertViaExt = 1
|
||||
} else {
|
||||
|
|
@ -382,7 +382,7 @@ func TestProcessorsTx(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
afterInsertFunc := func(bean interface{}) {
|
||||
afterInsertFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.AfterInsertedViaExt = 1
|
||||
} else {
|
||||
|
|
@ -497,7 +497,7 @@ func TestProcessorsTx(t *testing.T) {
|
|||
err = session.Begin()
|
||||
assert.NoError(t, err)
|
||||
|
||||
b4UpdateFunc := func(bean interface{}) {
|
||||
b4UpdateFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.B4UpdateViaExt = 1
|
||||
} else {
|
||||
|
|
@ -505,7 +505,7 @@ func TestProcessorsTx(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
afterUpdateFunc := func(bean interface{}) {
|
||||
afterUpdateFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.AfterUpdatedViaExt = 1
|
||||
} else {
|
||||
|
|
@ -671,7 +671,7 @@ func TestProcessorsTx(t *testing.T) {
|
|||
err = session.Begin()
|
||||
assert.NoError(t, err)
|
||||
|
||||
b4DeleteFunc := func(bean interface{}) {
|
||||
b4DeleteFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.B4DeleteViaExt = 1
|
||||
} else {
|
||||
|
|
@ -679,7 +679,7 @@ func TestProcessorsTx(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
afterDeleteFunc := func(bean interface{}) {
|
||||
afterDeleteFunc := func(bean any) {
|
||||
if v, ok := (bean).(*ProcessorsStruct); ok {
|
||||
v.AfterDeletedViaExt = 1
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -719,7 +719,7 @@ func TestSyncWithOptions(t *testing.T) {
|
|||
assert.ElementsMatch(t, getKeysFromMap(tableInfoFromStruct.Indexes), getKeysFromMap(getIndicesOfBeanFromDB(t, &SyncWithOpts1{})))
|
||||
}
|
||||
|
||||
func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.Index {
|
||||
func getIndicesOfBeanFromDB(t *testing.T, bean any) map[string]*schemas.Index {
|
||||
dbm, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ func TestIn(t *testing.T) {
|
|||
}
|
||||
|
||||
users = make([]Userinfo, 0)
|
||||
var idsInterface []interface{}
|
||||
var idsInterface []any
|
||||
for _, id := range ids {
|
||||
idsInterface = append(idsInterface, id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ func TestFind3(t *testing.T) {
|
|||
err = testEngine.Cols("`team`.`id`").
|
||||
Where("`team_user`.`org_id`=?", 1).
|
||||
And("`team_user`.`uid`=?", 2).
|
||||
Join("INNER", []interface{}{teamUser}, "`team_user`.`team_id`=`team`.`id`").
|
||||
Join("INNER", []any{teamUser}, "`team_user`.`team_id`=`team`.`id`").
|
||||
Find(&teams)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ func TestFind3(t *testing.T) {
|
|||
err = testEngine.Cols("`team`.`id`").
|
||||
Where("`tu`.`org_id`=?", 1).
|
||||
And("`tu`.`uid`=?", 2).
|
||||
Join("INNER", []interface{}{"team_user", "tu"}, "`tu`.`team_id`=`team`.`id`").
|
||||
Join("INNER", []any{"team_user", "tu"}, "`tu`.`team_id`=`team`.`id`").
|
||||
Find(&teams)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ func TestFind3(t *testing.T) {
|
|||
err = testEngine.Cols("`team`.`id`").
|
||||
Where("`tu`.`org_id`=?", 1).
|
||||
And("`tu`.`uid`=?", 2).
|
||||
Join("INNER", []interface{}{teamUser, "tu"}, "`tu`.`team_id`=`team`.`id`").
|
||||
Join("INNER", []any{teamUser, "tu"}, "`tu`.`team_id`=`team`.`id`").
|
||||
Find(&teams)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
@ -367,7 +367,7 @@ func TestFindInterface(t *testing.T) {
|
|||
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
username := testEngine.GetColumnMapper().Obj2Table("Username")
|
||||
var idsInterface []interface{}
|
||||
var idsInterface []any
|
||||
err := testEngine.Table(userinfo).Cols(username).Desc("id").Find(&idsInterface)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ func TestGetVar(t *testing.T) {
|
|||
assert.Equal(t, "1.5", valuesString["money"])
|
||||
|
||||
{
|
||||
valuesInter := make(map[string]interface{})
|
||||
valuesInter := make(map[string]any)
|
||||
has, err = testEngine.Table("get_var").Where("`id` = ?", 1).Select("*").Get(&valuesInter)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
|
@ -206,7 +206,7 @@ func TestGetVar(t *testing.T) {
|
|||
assert.Equal(t, "28", valuesSliceString[2])
|
||||
assert.Equal(t, "1.5", valuesSliceString[3])
|
||||
|
||||
valuesSliceInter := make([]interface{}, 5)
|
||||
valuesSliceInter := make([]any, 5)
|
||||
has, err = testEngine.Table("get_var").Get(&valuesSliceInter)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
|
@ -727,7 +727,7 @@ func TestGetViaMapCond(t *testing.T) {
|
|||
r GetViaMapCond
|
||||
platformStr = colMapper.Obj2Table("Platform")
|
||||
indexStr = colMapper.Obj2Table("Index")
|
||||
query = map[string]interface{}{
|
||||
query = map[string]any{
|
||||
platformStr: 1,
|
||||
indexStr: 1,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func TestInsertMulti(t *testing.T) {
|
|||
assert.EqualValues(t, 3, num)
|
||||
}
|
||||
|
||||
func insertMultiDatas(step int, datas interface{}) (num int64, err error) {
|
||||
func insertMultiDatas(step int, datas any) (num int64, err error) {
|
||||
sliceValue := reflect.Indirect(reflect.ValueOf(datas))
|
||||
var iLen int64
|
||||
if sliceValue.Kind() != reflect.Slice {
|
||||
|
|
@ -62,7 +62,7 @@ func insertMultiDatas(step int, datas interface{}) (num int64, err error) {
|
|||
defer session.Close()
|
||||
|
||||
if err = callbackLooper(datas, step,
|
||||
func(innerDatas interface{}) error {
|
||||
func(innerDatas any) error {
|
||||
n, e := session.InsertMulti(innerDatas)
|
||||
if e != nil {
|
||||
return e
|
||||
|
|
@ -77,7 +77,7 @@ func insertMultiDatas(step int, datas interface{}) (num int64, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func callbackLooper(datas interface{}, step int, actionFunc func(interface{}) error) (err error) {
|
||||
func callbackLooper(datas any, step int, actionFunc func(any) error) (err error) {
|
||||
sliceValue := reflect.Indirect(reflect.ValueOf(datas))
|
||||
if sliceValue.Kind() != reflect.Slice {
|
||||
return fmt.Errorf("not slice")
|
||||
|
|
@ -94,7 +94,7 @@ func callbackLooper(datas interface{}, step int, actionFunc func(interface{}) er
|
|||
} else {
|
||||
tempLen = sliceValue.Len()
|
||||
}
|
||||
var tempInterface []interface{}
|
||||
var tempInterface []any
|
||||
for j := i; j < tempLen; j++ {
|
||||
tempInterface = append(tempInterface, sliceValue.Index(j).Interface())
|
||||
}
|
||||
|
|
@ -482,7 +482,7 @@ func TestInsertMulti2Interface(t *testing.T) {
|
|||
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
users := []interface{}{
|
||||
users := []any{
|
||||
Userinfo{Username: "xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
|
||||
Userinfo{Username: "xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
|
||||
Userinfo{Username: "xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
|
||||
|
|
@ -496,7 +496,7 @@ func TestInsertMulti2Interface(t *testing.T) {
|
|||
}
|
||||
assert.EqualValues(t, len(users), cnt)
|
||||
|
||||
users2 := []interface{}{
|
||||
users2 := []any{
|
||||
&Userinfo{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
|
||||
&Userinfo{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
|
||||
&Userinfo{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
|
||||
|
|
@ -683,7 +683,7 @@ func TestInsertMap(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(InsertMap))
|
||||
|
||||
cnt, err := testEngine.Table(new(InsertMap)).Insert(map[string]interface{}{
|
||||
cnt, err := testEngine.Table(new(InsertMap)).Insert(map[string]any{
|
||||
"width": 20,
|
||||
"height": 10,
|
||||
"name": "lunny",
|
||||
|
|
@ -699,7 +699,7 @@ func TestInsertMap(t *testing.T) {
|
|||
assert.EqualValues(t, 10, im.Height)
|
||||
assert.EqualValues(t, "lunny", im.Name)
|
||||
|
||||
cnt, err = testEngine.Table("insert_map").Insert(map[string]interface{}{
|
||||
cnt, err = testEngine.Table("insert_map").Insert(map[string]any{
|
||||
"width": 30,
|
||||
"height": 10,
|
||||
"name": "lunny",
|
||||
|
|
@ -718,7 +718,7 @@ func TestInsertMap(t *testing.T) {
|
|||
assert.EqualValues(t, 10, ims[1].Height)
|
||||
assert.EqualValues(t, "lunny", ims[1].Name)
|
||||
|
||||
cnt, err = testEngine.Table("insert_map").Insert([]map[string]interface{}{
|
||||
cnt, err = testEngine.Table("insert_map").Insert([]map[string]any{
|
||||
{
|
||||
"width": 40,
|
||||
"height": 10,
|
||||
|
|
@ -797,7 +797,7 @@ func TestInsertWhere(t *testing.T) {
|
|||
|
||||
inserted, err = testEngine.Table(new(InsertWhere)).Where("`repo_id`=?", 1).
|
||||
SetExpr("`index`", "coalesce(MAX(`index`),0)+1").
|
||||
Insert(map[string]interface{}{
|
||||
Insert(map[string]any{
|
||||
"repo_id": 1,
|
||||
"width": 20,
|
||||
"height": 40,
|
||||
|
|
@ -834,7 +834,7 @@ func TestInsertWhere(t *testing.T) {
|
|||
|
||||
inserted, err = testEngine.Table(new(InsertWhere)).Where("`repo_id`=?", 1).
|
||||
SetExpr("`index`", "coalesce(MAX(`index`),0)+1").
|
||||
Insert(map[string]interface{}{
|
||||
Insert(map[string]any{
|
||||
"repo_id": 1,
|
||||
"name": "10';delete * from insert_where; --",
|
||||
})
|
||||
|
|
@ -850,7 +850,7 @@ func TestInsertWhere(t *testing.T) {
|
|||
|
||||
inserted, err = testEngine.Table(new(InsertWhere)).Where("`repo_id`=?", 1).
|
||||
SetExpr("`index`", "coalesce(MAX(`index`),0)+1").
|
||||
Insert(map[string]interface{}{
|
||||
Insert(map[string]any{
|
||||
"repo_id": 1,
|
||||
"name": "10\\';delete * from insert_where; --",
|
||||
})
|
||||
|
|
@ -910,7 +910,7 @@ func TestInsertExpr2(t *testing.T) {
|
|||
SetExpr("is_draft", true).
|
||||
SetExpr("num_commits", 0).
|
||||
SetExpr("sha1", "").
|
||||
Insert(map[string]interface{}{
|
||||
Insert(map[string]any{
|
||||
"repo_id": 1,
|
||||
"is_tag": true,
|
||||
})
|
||||
|
|
@ -947,7 +947,7 @@ func TestMultipleInsertTableName(t *testing.T) {
|
|||
err := trans.Begin()
|
||||
assert.NoError(t, err)
|
||||
|
||||
rtArr := []interface{}{
|
||||
rtArr := []any{
|
||||
[]*NightlyRate{
|
||||
{ID: 1},
|
||||
{ID: 2},
|
||||
|
|
@ -978,7 +978,7 @@ func TestInsertMultiWithOmit(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync(new(TestMultiOmit)))
|
||||
|
||||
l := []interface{}{
|
||||
l := []any{
|
||||
TestMultiOmit{Id: 1, Name: "1", Omitted: "1"},
|
||||
TestMultiOmit{Id: 2, Name: "1", Omitted: "2"},
|
||||
TestMultiOmit{Id: 3, Name: "1", Omitted: "3"},
|
||||
|
|
@ -1142,7 +1142,7 @@ func TestInsertMultipleMap(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(InsertMultipleMap))
|
||||
|
||||
cnt, err := testEngine.Table(new(InsertMultipleMap)).Insert([]map[string]interface{}{
|
||||
cnt, err := testEngine.Table(new(InsertMultipleMap)).Insert([]map[string]any{
|
||||
{
|
||||
"width": 20,
|
||||
"height": 10,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func TestIterate(t *testing.T) {
|
|||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
cnt = 0
|
||||
err = testEngine.Iterate(new(UserIterate), func(i int, bean interface{}) error {
|
||||
err = testEngine.Iterate(new(UserIterate), func(i int, bean any) error {
|
||||
user := bean.(*UserIterate)
|
||||
if cnt == 0 {
|
||||
assert.EqualValues(t, 1, user.Id)
|
||||
|
|
@ -69,7 +69,7 @@ func TestBufferIterate(t *testing.T) {
|
|||
}
|
||||
|
||||
cnt := 0
|
||||
err := testEngine.BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean interface{}) error {
|
||||
err := testEngine.BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean any) error {
|
||||
user := bean.(*UserBufferIterate)
|
||||
assert.EqualValues(t, cnt+1, user.Id)
|
||||
assert.EqualValues(t, true, user.IsMan)
|
||||
|
|
@ -80,7 +80,7 @@ func TestBufferIterate(t *testing.T) {
|
|||
assert.EqualValues(t, size, cnt)
|
||||
|
||||
cnt = 0
|
||||
err = testEngine.Limit(20).BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean interface{}) error {
|
||||
err = testEngine.Limit(20).BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean any) error {
|
||||
user := bean.(*UserBufferIterate)
|
||||
assert.EqualValues(t, cnt+1, user.Id)
|
||||
assert.EqualValues(t, true, user.IsMan)
|
||||
|
|
@ -91,7 +91,7 @@ func TestBufferIterate(t *testing.T) {
|
|||
assert.EqualValues(t, size, cnt)
|
||||
|
||||
cnt = 0
|
||||
err = testEngine.Limit(7).BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean interface{}) error {
|
||||
err = testEngine.Limit(7).BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean any) error {
|
||||
user := bean.(*UserBufferIterate)
|
||||
assert.EqualValues(t, cnt+1, user.Id)
|
||||
assert.EqualValues(t, true, user.IsMan)
|
||||
|
|
@ -102,7 +102,7 @@ func TestBufferIterate(t *testing.T) {
|
|||
assert.EqualValues(t, 7, cnt)
|
||||
|
||||
cnt = 0
|
||||
err = testEngine.Where("`id` <= 10").BufferSize(2).Iterate(new(UserBufferIterate), func(i int, bean interface{}) error {
|
||||
err = testEngine.Where("`id` <= 10").BufferSize(2).Iterate(new(UserBufferIterate), func(i int, bean any) error {
|
||||
user := bean.(*UserBufferIterate)
|
||||
assert.EqualValues(t, cnt+1, user.Id)
|
||||
assert.EqualValues(t, true, user.IsMan)
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func TestQueryString2(t *testing.T) {
|
|||
assert.True(t, "0" == records[0]["msg"] || "false" == records[0]["msg"])
|
||||
}
|
||||
|
||||
func toBool(i interface{}) bool {
|
||||
func toBool(i any) bool {
|
||||
switch t := i.(type) {
|
||||
case int32:
|
||||
return t > 0
|
||||
|
|
@ -422,7 +422,7 @@ func TestQueryBLOBInMySQL(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
arr := make([][]interface{}, 0)
|
||||
arr := make([][]any, 0)
|
||||
err = testEngine.Table(testEngine.Quote(testEngine.TableName("avatar", true))).Cols("avatar").Find(&arr)
|
||||
assert.NoError(t, err)
|
||||
for i, record := range arr {
|
||||
|
|
@ -433,7 +433,7 @@ func TestQueryBLOBInMySQL(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
arr := make([]map[string]interface{}, 0)
|
||||
arr := make([]map[string]any, 0)
|
||||
err = testEngine.Table(testEngine.Quote(testEngine.TableName("avatar", true))).Cols("avatar").Find(&arr)
|
||||
assert.NoError(t, err)
|
||||
for i, record := range arr {
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ func TestInsertMulti2InterfaceTransaction(t *testing.T) {
|
|||
err := session.Begin()
|
||||
assert.NoError(t, err)
|
||||
|
||||
users := []interface{}{
|
||||
users := []any{
|
||||
&Multi2InterfaceTransaction{Name: "a", Alias: "A"},
|
||||
&Multi2InterfaceTransaction{Name: "b", Alias: "B"},
|
||||
&Multi2InterfaceTransaction{Name: "c", Alias: "C"},
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ func TestUpdateMap(t *testing.T) {
|
|||
_, err := testEngine.Insert(&tb)
|
||||
assert.NoError(t, err)
|
||||
|
||||
cnt, err := testEngine.Table("update_table").Where("`id` = ?", tb.Id).Update(map[string]interface{}{
|
||||
cnt, err := testEngine.Table("update_table").Where("`id` = ?", tb.Id).Update(map[string]any{
|
||||
"name": "test2",
|
||||
"age": 36,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
cnt, err = testEngine.Table("update_table").ID(tb.Id).Update(map[string]interface{}{
|
||||
cnt, err = testEngine.Table("update_table").ID(tb.Id).Update(map[string]any{
|
||||
"name": "test2",
|
||||
"age": 36,
|
||||
})
|
||||
|
|
@ -51,7 +51,7 @@ func TestUpdateMap(t *testing.T) {
|
|||
assert.True(t, statements.IsIDConditionWithNoTableErr(err))
|
||||
assert.EqualValues(t, 0, cnt)
|
||||
|
||||
cnt, err = testEngine.Table("update_table").Update(map[string]interface{}{
|
||||
cnt, err = testEngine.Table("update_table").Update(map[string]any{
|
||||
"name": "test2",
|
||||
"age": 36,
|
||||
}, &UpdateTable{
|
||||
|
|
@ -270,7 +270,7 @@ func TestWithIn(t *testing.T) {
|
|||
assert.EqualValues(t, 3, cnt)
|
||||
}
|
||||
|
||||
type Condi map[string]interface{}
|
||||
type Condi map[string]any
|
||||
|
||||
type UpdateAllCols struct {
|
||||
Id int64
|
||||
|
|
@ -305,7 +305,7 @@ func TestUpdateMap2(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(UpdateMustCols))
|
||||
|
||||
_, err := testEngine.Table("update_must_cols").Where("`id` =?", 1).Update(map[string]interface{}{
|
||||
_, err := testEngine.Table("update_must_cols").Where("`id` =?", 1).Update(map[string]any{
|
||||
"bool": true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -810,17 +810,17 @@ func TestNewUpdate(t *testing.T) {
|
|||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TbUserInfo struct {
|
||||
Id int64 `xorm:"pk autoincr unique BIGINT" json:"id"`
|
||||
Phone string `xorm:"not null unique VARCHAR(20)" json:"phone"`
|
||||
UserName string `xorm:"VARCHAR(20)" json:"user_name"`
|
||||
Gender int `xorm:"default 0 INTEGER" json:"gender"`
|
||||
Pw string `xorm:"VARCHAR(100)" json:"pw"`
|
||||
Token string `xorm:"TEXT" json:"token"`
|
||||
Avatar string `xorm:"TEXT" json:"avatar"`
|
||||
Extras interface{} `xorm:"JSON" json:"extras"`
|
||||
Created time.Time `xorm:"DATETIME created"`
|
||||
Updated time.Time `xorm:"DATETIME updated"`
|
||||
Deleted time.Time `xorm:"DATETIME deleted"`
|
||||
Id int64 `xorm:"pk autoincr unique BIGINT" json:"id"`
|
||||
Phone string `xorm:"not null unique VARCHAR(20)" json:"phone"`
|
||||
UserName string `xorm:"VARCHAR(20)" json:"user_name"`
|
||||
Gender int `xorm:"default 0 INTEGER" json:"gender"`
|
||||
Pw string `xorm:"VARCHAR(100)" json:"pw"`
|
||||
Token string `xorm:"TEXT" json:"token"`
|
||||
Avatar string `xorm:"TEXT" json:"avatar"`
|
||||
Extras any `xorm:"JSON" json:"extras"`
|
||||
Created time.Time `xorm:"DATETIME created"`
|
||||
Updated time.Time `xorm:"DATETIME updated"`
|
||||
Deleted time.Time `xorm:"DATETIME deleted"`
|
||||
}
|
||||
|
||||
assertSync(t, new(TbUserInfo))
|
||||
|
|
@ -965,7 +965,7 @@ func TestUpdateMapCondition(t *testing.T) {
|
|||
|
||||
cnt, err := testEngine.Update(&UpdateMapCondition{
|
||||
String: "string1",
|
||||
}, map[string]interface{}{
|
||||
}, map[string]any{
|
||||
"id": c.Id,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -1001,7 +1001,7 @@ func TestUpdateMapContent(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 18, c.Age)
|
||||
|
||||
cnt, err := testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]interface{}{"age": 0})
|
||||
cnt, err := testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]any{"age": 0})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
|
|
@ -1011,7 +1011,7 @@ func TestUpdateMapContent(t *testing.T) {
|
|||
assert.True(t, has)
|
||||
assert.EqualValues(t, 0, c1.Age)
|
||||
|
||||
cnt, err = testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]interface{}{
|
||||
cnt, err = testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]any{
|
||||
"age": 16,
|
||||
"is_man": false,
|
||||
"gender": 2,
|
||||
|
|
@ -1027,7 +1027,7 @@ func TestUpdateMapContent(t *testing.T) {
|
|||
assert.EqualValues(t, false, c2.IsMan)
|
||||
assert.EqualValues(t, 2, c2.Gender)
|
||||
|
||||
cnt, err = testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]interface{}{
|
||||
cnt, err = testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]any{
|
||||
"age": 15,
|
||||
"is_man": true,
|
||||
"gender": 1,
|
||||
|
|
@ -1144,7 +1144,7 @@ func TestUpdateDeleted(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 0, cnt)
|
||||
|
||||
cnt, err = testEngine.Table(&UpdateDeletedStruct{}).ID(s.Id).Update(map[string]interface{}{
|
||||
cnt, err = testEngine.Table(&UpdateDeletedStruct{}).ID(s.Id).Update(map[string]any{
|
||||
"name": "test1",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -1288,13 +1288,13 @@ func TestUpdateMap3(t *testing.T) {
|
|||
|
||||
assertSync(t, new(UpdateMapUser))
|
||||
|
||||
_, err := testEngine.Table(new(UpdateMapUser)).Insert(map[string]interface{}{
|
||||
_, err := testEngine.Table(new(UpdateMapUser)).Insert(map[string]any{
|
||||
"Fname": "first user name",
|
||||
"Fver": 1,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
update := map[string]interface{}{
|
||||
update := map[string]any{
|
||||
"Fname": "user name",
|
||||
"Fver": 1,
|
||||
}
|
||||
|
|
@ -1302,7 +1302,7 @@ func TestUpdateMap3(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, rows)
|
||||
|
||||
update = map[string]interface{}{
|
||||
update = map[string]any{
|
||||
"Name": "user name",
|
||||
"Ver": 1,
|
||||
}
|
||||
|
|
@ -1376,10 +1376,10 @@ func TestUpdateMultiplePK(t *testing.T) {
|
|||
assert.EqualValues(t, 1, num)
|
||||
|
||||
test.Value = "4"
|
||||
_, err = testEngine.ID([]interface{}{test.Id, test.Name}).Update(test)
|
||||
_, err = testEngine.ID([]any{test.Id, test.Name}).Update(test)
|
||||
assert.NoError(t, err)
|
||||
|
||||
type MySlice []interface{}
|
||||
type MySlice []any
|
||||
test.Value = "5"
|
||||
_, err = testEngine.ID(&MySlice{test.Id, test.Name}).Update(test)
|
||||
assert.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ func createEngine(dbType, connStr string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tableNames := make([]interface{}, 0, len(tables))
|
||||
tableNames := make([]any, 0, len(tables))
|
||||
for _, table := range tables {
|
||||
tableNames = append(tableNames, table.Name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func (CustomStruct) String() string {
|
|||
return "CustomStruct"
|
||||
}
|
||||
|
||||
func (m *CustomStruct) Scan(value interface{}) error {
|
||||
func (m *CustomStruct) Scan(value any) error {
|
||||
if value == nil {
|
||||
m.Year, m.Month, m.Day = 0, 0, 0
|
||||
return nil
|
||||
|
|
@ -261,7 +261,7 @@ func TestNullStructIterate(t *testing.T) {
|
|||
|
||||
if true {
|
||||
err := testEngine.Where("`age` IS NOT NULL").OrderBy("age").Iterate(new(NullStruct),
|
||||
func(i int, bean interface{}) error {
|
||||
func(i int, bean any) error {
|
||||
nultype := bean.(*NullStruct)
|
||||
fmt.Println(i, nultype)
|
||||
return nil
|
||||
|
|
|
|||
12
tx.go
12
tx.go
|
|
@ -65,7 +65,7 @@ func (session *Session) Commit() error {
|
|||
}
|
||||
|
||||
// handle processors after tx committed
|
||||
closureCallFunc := func(closuresPtr *[]func(interface{}), bean interface{}) {
|
||||
closureCallFunc := func(closuresPtr *[]func(any), bean any) {
|
||||
if closuresPtr != nil {
|
||||
for _, closure := range *closuresPtr {
|
||||
closure(bean)
|
||||
|
|
@ -76,27 +76,27 @@ func (session *Session) Commit() error {
|
|||
for bean, closuresPtr := range session.afterInsertBeans {
|
||||
closureCallFunc(closuresPtr, bean)
|
||||
|
||||
if processor, ok := interface{}(bean).(AfterInsertProcessor); ok {
|
||||
if processor, ok := any(bean).(AfterInsertProcessor); ok {
|
||||
processor.AfterInsert()
|
||||
}
|
||||
}
|
||||
for bean, closuresPtr := range session.afterUpdateBeans {
|
||||
closureCallFunc(closuresPtr, bean)
|
||||
|
||||
if processor, ok := interface{}(bean).(AfterUpdateProcessor); ok {
|
||||
if processor, ok := any(bean).(AfterUpdateProcessor); ok {
|
||||
processor.AfterUpdate()
|
||||
}
|
||||
}
|
||||
for bean, closuresPtr := range session.afterDeleteBeans {
|
||||
closureCallFunc(closuresPtr, bean)
|
||||
|
||||
if processor, ok := interface{}(bean).(AfterDeleteProcessor); ok {
|
||||
if processor, ok := any(bean).(AfterDeleteProcessor); ok {
|
||||
processor.AfterDelete()
|
||||
}
|
||||
}
|
||||
cleanUpFunc := func(slices *map[interface{}]*[]func(interface{})) {
|
||||
cleanUpFunc := func(slices *map[any]*[]func(any)) {
|
||||
if len(*slices) > 0 {
|
||||
*slices = make(map[interface{}]*[]func(interface{}))
|
||||
*slices = make(map[any]*[]func(any))
|
||||
}
|
||||
}
|
||||
cleanUpFunc(&session.afterInsertBeans)
|
||||
|
|
|
|||
26
update.go
26
update.go
|
|
@ -18,12 +18,12 @@ var (
|
|||
ErrNoColumnsTobeUpdated = statements.ErrNoColumnsTobeUpdated
|
||||
)
|
||||
|
||||
func (session *Session) genAutoCond(condiBean interface{}) (builder.Cond, error) {
|
||||
func (session *Session) genAutoCond(condiBean any) (builder.Cond, error) {
|
||||
if session.statement.NoAutoCondition {
|
||||
return builder.NewCond(), nil
|
||||
}
|
||||
|
||||
if c, ok := condiBean.(map[string]interface{}); ok {
|
||||
if c, ok := condiBean.(map[string]any); ok {
|
||||
eq := make(builder.Eq)
|
||||
for k, v := range c {
|
||||
eq[session.engine.Quote(k)] = v
|
||||
|
|
@ -60,7 +60,7 @@ func (session *Session) genAutoCond(condiBean interface{}) (builder.Cond, error)
|
|||
// 1.bool will defaultly be updated content nor conditions
|
||||
// You should call UseBool if you have bool to use.
|
||||
// 2.float32 & float64 may be not inexact as conditions
|
||||
func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int64, error) {
|
||||
func (session *Session) Update(bean any, condiBean ...any) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
|
@ -79,13 +79,13 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
closure(bean)
|
||||
}
|
||||
cleanupProcessorsClosures(&session.beforeClosures) // cleanup after used
|
||||
if processor, ok := interface{}(bean).(BeforeUpdateProcessor); ok {
|
||||
if processor, ok := any(bean).(BeforeUpdateProcessor); ok {
|
||||
processor.BeforeUpdate()
|
||||
}
|
||||
// --
|
||||
|
||||
var colNames []string
|
||||
var args []interface{}
|
||||
var args []any
|
||||
var err error
|
||||
isMap := t.Kind() == reflect.Map
|
||||
isStruct := t.Kind() == reflect.Struct
|
||||
|
|
@ -109,7 +109,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
}
|
||||
} else if isMap {
|
||||
colNames = make([]string, 0)
|
||||
args = make([]interface{}, 0)
|
||||
args = make([]any, 0)
|
||||
bValue := reflect.Indirect(reflect.ValueOf(bean))
|
||||
|
||||
for _, v := range bValue.MapKeys() {
|
||||
|
|
@ -139,7 +139,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
|
||||
colName := col.Name
|
||||
if isStruct {
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
session.afterClosures = append(session.afterClosures, func(bean any) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
|
|
@ -206,7 +206,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
for _, closure := range session.afterClosures {
|
||||
closure(bean)
|
||||
}
|
||||
if processor, ok := interface{}(bean).(AfterUpdateProcessor); ok {
|
||||
if processor, ok := any(bean).(AfterUpdateProcessor); ok {
|
||||
session.engine.logger.Debugf("[event] %v has after update processor", tableName)
|
||||
processor.AfterUpdate()
|
||||
}
|
||||
|
|
@ -216,13 +216,13 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
if value, has := session.afterUpdateBeans[bean]; has && value != nil {
|
||||
*value = append(*value, session.afterClosures...)
|
||||
} else {
|
||||
afterClosures := make([]func(interface{}), lenAfterClosures)
|
||||
afterClosures := make([]func(any), lenAfterClosures)
|
||||
copy(afterClosures, session.afterClosures)
|
||||
// FIXME: if bean is a map type, it will panic because map cannot be as map key
|
||||
session.afterUpdateBeans[bean] = &afterClosures
|
||||
}
|
||||
} else {
|
||||
if _, ok := interface{}(bean).(AfterUpdateProcessor); ok {
|
||||
if _, ok := any(bean).(AfterUpdateProcessor); ok {
|
||||
session.afterUpdateBeans[bean] = nil
|
||||
}
|
||||
}
|
||||
|
|
@ -233,10 +233,10 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interface{}, error) {
|
||||
func (session *Session) genUpdateColumns(bean any) ([]string, []any, error) {
|
||||
table := session.statement.RefTable
|
||||
colNames := make([]string, 0, len(table.ColumnsSeq()))
|
||||
args := make([]interface{}, 0, len(table.ColumnsSeq()))
|
||||
args := make([]any, 0, len(table.ColumnsSeq()))
|
||||
|
||||
for _, col := range table.Columns() {
|
||||
if !col.IsVersion && !col.IsCreated && !col.IsUpdated {
|
||||
|
|
@ -292,7 +292,7 @@ func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interfac
|
|||
args = append(args, val)
|
||||
|
||||
colName := col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
session.afterClosures = append(session.afterClosures, func(bean any) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue