diff --git a/abstract/base.go b/abstract/base.go index 52733a5..a14066d 100644 --- a/abstract/base.go +++ b/abstract/base.go @@ -19,17 +19,17 @@ import ( // Date : 15:06 2023/10/14 type Base interface { // Create 创建数据 - Create(dbInstance *gorm.DB, data interface{}, optionList ...database.SetOption) error + Create(dbInstance *gorm.DB, data any, optionList ...database.SetOption) error // Update 更新数据 - Update(dbInstance *gorm.DB, updateData interface{}, optionFuncList ...database.SetOption) (int64, error) + Update(dbInstance *gorm.DB, updateData any, optionFuncList ...database.SetOption) (int64, error) // UpdateOne 更新一条数据 - UpdateOne(dbInstance *gorm.DB, updateData interface{}, optionFuncList ...database.SetOption) (int64, error) + UpdateOne(dbInstance *gorm.DB, updateData any, optionFuncList ...database.SetOption) (int64, error) // List 查询数据列表 - List(dbInstance *gorm.DB, result interface{}, optionFuncList ...database.SetOption) error + List(dbInstance *gorm.DB, result any, optionFuncList ...database.SetOption) error // Delete 删除数据 - Delete(dbInstance *gorm.DB, dataModel interface{}, optionFuncList ...database.SetOption) (int64, error) + Delete(dbInstance *gorm.DB, dataModel any, optionFuncList ...database.SetOption) (int64, error) // Detail 数据详情 - Detail(dbInstance *gorm.DB, result interface{}, optionFuncList ...database.SetOption) error + Detail(dbInstance *gorm.DB, result any, optionFuncList ...database.SetOption) error // IsNotFound 错误是否为数据不存在 IsNotFound(err error) bool // Count 查询数据数量 diff --git a/base.go b/base.go index c520734..b9cff80 100644 --- a/base.go +++ b/base.go @@ -25,7 +25,7 @@ type BaseDao struct { // Author : go_developer@163.com<白茶清欢> // // Date : 8:06 下午 2021/8/8 -func (b *BaseDao) Create(dbInstance *gorm.DB, data interface{}, optionList ...SetOption) error { +func (b *BaseDao) Create(dbInstance *gorm.DB, data any, optionList ...SetOption) error { o := &Option{} for _, itemFunc := range optionList { itemFunc(o) @@ -42,7 +42,7 @@ func (b *BaseDao) Create(dbInstance *gorm.DB, data interface{}, optionList ...Se // Author : go_developer@163.com<白茶清欢> // // Date : 8:12 下午 2021/8/8 -func (b *BaseDao) Update(dbInstance *gorm.DB, updateData interface{}, optionFuncList ...SetOption) (int64, error) { +func (b *BaseDao) Update(dbInstance *gorm.DB, updateData any, optionFuncList ...SetOption) (int64, error) { dbInstance = b.setTxCondition(dbInstance, optionFuncList...) r := dbInstance.Updates(updateData) return r.RowsAffected, r.Error @@ -53,7 +53,7 @@ func (b *BaseDao) Update(dbInstance *gorm.DB, updateData interface{}, optionFunc // Author : go_developer@163.com<白茶清欢> // // Date : 17:05 2024/1/13 -func (b *BaseDao) UpdateOne(dbInstance *gorm.DB, updateData interface{}, optionFuncList ...SetOption) (int64, error) { +func (b *BaseDao) UpdateOne(dbInstance *gorm.DB, updateData any, optionFuncList ...SetOption) (int64, error) { optionFuncList = append(optionFuncList, WithLimit(1, 0)) return b.Update(dbInstance, updateData, optionFuncList...) } @@ -63,7 +63,7 @@ func (b *BaseDao) UpdateOne(dbInstance *gorm.DB, updateData interface{}, optionF // Author : go_developer@163.com<白茶清欢> // // Date : 8:14 下午 2021/8/8 -func (b *BaseDao) List(dbInstance *gorm.DB, result interface{}, optionFuncList ...SetOption) error { +func (b *BaseDao) List(dbInstance *gorm.DB, result any, optionFuncList ...SetOption) error { dbInstance = b.setTxCondition(dbInstance, optionFuncList...) return dbInstance.Find(result).Error } @@ -73,7 +73,7 @@ func (b *BaseDao) List(dbInstance *gorm.DB, result interface{}, optionFuncList . // Author : go_developer@163.com<白茶清欢> // // Date : 11:46 2023/2/9 -func (b *BaseDao) Delete(dbInstance *gorm.DB, dataModel interface{}, optionFuncList ...SetOption) (int64, error) { +func (b *BaseDao) Delete(dbInstance *gorm.DB, dataModel any, optionFuncList ...SetOption) (int64, error) { dbInstance = dbInstance.Model(dataModel) dbInstance = b.setTxCondition(dbInstance, optionFuncList...).Delete(dataModel) return dbInstance.RowsAffected, dbInstance.Error @@ -84,7 +84,7 @@ func (b *BaseDao) Delete(dbInstance *gorm.DB, dataModel interface{}, optionFuncL // Author : go_developer@163.com<白茶清欢> // // Date : 8:25 下午 2021/8/8 -func (b *BaseDao) Detail(dbInstance *gorm.DB, result interface{}, optionFuncList ...SetOption) error { +func (b *BaseDao) Detail(dbInstance *gorm.DB, result any, optionFuncList ...SetOption) error { dbInstance = b.setTxCondition(dbInstance, optionFuncList...) return dbInstance.First(result).Error } @@ -94,12 +94,12 @@ func (b *BaseDao) Detail(dbInstance *gorm.DB, result interface{}, optionFuncList // Author : go_developer@163.com<白茶清欢> // // Date : 14:14 2023/10/15 -func (b *BaseDao) DetailByPrimaryID(dbInstance *gorm.DB, result interface{}, primaryID interface{}, primaryKey ...string) error { +func (b *BaseDao) DetailByPrimaryID(dbInstance *gorm.DB, result any, primaryID any, primaryKey ...string) error { primaryKeyField := "id" if len(primaryKey) > 0 { primaryKeyField = primaryKey[0] } - return b.Detail(dbInstance, result, WithWhere(map[string]interface{}{ + return b.Detail(dbInstance, result, WithWhere(map[string]any{ primaryKeyField: primaryID, })) } @@ -253,7 +253,7 @@ func (b *BaseDao) setTxCondition(tx *gorm.DB, optionFuncList ...SetOption) *gorm // or 语句 if nil != o.OR { expression := "" - valList := make([]interface{}, 0) + valList := make([]any, 0) for _, o := range o.OR { if len(expression) > 0 { expression = expression + " OR " diff --git a/option.go b/option.go index 3008b24..31a4319 100644 --- a/option.go +++ b/option.go @@ -24,8 +24,8 @@ type SetOption func(o *Option) // // Date : 20:07 2022/7/23 type ORCondition struct { - Express string `json:"express"` // 表达式 - Value interface{} `json:"value"` // 绑定值 + Express string `json:"express"` // 表达式 + Value any `json:"value"` // 绑定值 } // Option 扩展选项 @@ -34,20 +34,20 @@ type ORCondition struct { // // Date : 8:05 下午 2021/8/8 type Option struct { - Model interface{} `json:"-"` // 操作model - Table string `json:"table"` // 查询的数据表 - Limit int `json:"limit"` // 限制数量 - Offset int `json:"offset"` // 偏移量 - In map[string]interface{} `json:"in"` // in语句 - NotIn map[string]interface{} `json:"not_in"` // not in语句 - Where map[string]interface{} `json:"where"` // where 条件 - Start map[string]interface{} `json:"start"` // >= 条件 - End map[string]interface{} `json:"end"` // < 条件 - Like map[string]string `json:"like"` // like 语句 - NotLike map[string]string `json:"not_like"` // not like 语句 - NotEqual map[string]interface{} `json:"not_equal"` // != 语句 - Order []string `json:"order"` // 排序规则 - OR []*ORCondition `json:"or"` // or 语句, or 和其他属性 and 关系, 内部 OR 关系 + Model any `json:"-"` // 操作model + Table string `json:"table"` // 查询的数据表 + Limit int `json:"limit"` // 限制数量 + Offset int `json:"offset"` // 偏移量 + In map[string]any `json:"in"` // in语句 + NotIn map[string]any `json:"not_in"` // not in语句 + Where map[string]any `json:"where"` // where 条件 + Start map[string]any `json:"start"` // >= 条件 + End map[string]any `json:"end"` // < 条件 + Like map[string]string `json:"like"` // like 语句 + NotLike map[string]string `json:"not_like"` // not like 语句 + NotEqual map[string]any `json:"not_equal"` // != 语句 + Order []string `json:"order"` // 排序规则 + OR []*ORCondition `json:"or"` // or 语句, or 和其他属性 and 关系, 内部 OR 关系 } // WithModel ... @@ -55,7 +55,7 @@ type Option struct { // Author : go_developer@163.com<白茶清欢> // // Date : 15:18 2024/1/15 -func WithModel(model interface{}) SetOption { +func WithModel(model any) SetOption { return func(o *Option) { o.Model = model } @@ -80,7 +80,7 @@ func WithTable(tableName string) SetOption { func WithWhere[T op_type.BaseType](where map[string]T) SetOption { return func(o *Option) { if nil == o.Where { - o.Where = make(map[string]interface{}) + o.Where = make(map[string]any) } for field, value := range where { o.Where[field] = value @@ -131,7 +131,7 @@ func WithIn[T op_type.Array](field string, value T) SetOption { return } if nil == o.In { - o.In = make(map[string]interface{}) + o.In = make(map[string]any) } o.In[field] = value } @@ -145,7 +145,7 @@ func WithIn[T op_type.Array](field string, value T) SetOption { func WithBatchIn[T op_type.Array](batchIn map[string]T) SetOption { return func(o *Option) { if nil == o.In { - o.In = make(map[string]interface{}) + o.In = make(map[string]any) } for field, value := range batchIn { WithIn(field, value) @@ -161,7 +161,7 @@ func WithBatchIn[T op_type.Array](batchIn map[string]T) SetOption { func WithNotIn[T op_type.Array](field string, value T) SetOption { return func(o *Option) { if nil == o.NotIn { - o.NotIn = make(map[string]interface{}) + o.NotIn = make(map[string]any) } if value == nil || len(value) == 0 { return @@ -178,7 +178,7 @@ func WithNotIn[T op_type.Array](field string, value T) SetOption { func WithBatchNotIn[T op_type.Array](data map[string]T) SetOption { return func(o *Option) { if nil == o.NotIn { - o.NotIn = make(map[string]interface{}) + o.NotIn = make(map[string]any) } for field, value := range data { if value == nil || len(value) == 0 { @@ -194,10 +194,10 @@ func WithBatchNotIn[T op_type.Array](data map[string]T) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 17:01 2022/5/15 -func WithStart(field string, value interface{}) SetOption { +func WithStart(field string, value any) SetOption { return func(o *Option) { if nil == o.Start { - o.Start = make(map[string]interface{}) + o.Start = make(map[string]any) } o.Start[field] = value } @@ -208,10 +208,10 @@ func WithStart(field string, value interface{}) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 17:03 2022/5/15 -func WithBatchStart(data map[string]interface{}) SetOption { +func WithBatchStart(data map[string]any) SetOption { return func(o *Option) { if nil == o.Start { - o.Start = make(map[string]interface{}) + o.Start = make(map[string]any) } for field, value := range data { o.Start[field] = value @@ -224,10 +224,10 @@ func WithBatchStart(data map[string]interface{}) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 17:07 2022/5/15 -func WithEnd(field string, value interface{}) SetOption { +func WithEnd(field string, value any) SetOption { return func(o *Option) { if nil == o.End { - o.End = make(map[string]interface{}) + o.End = make(map[string]any) } o.End[field] = value } @@ -238,10 +238,10 @@ func WithEnd(field string, value interface{}) SetOption { // Author : go_developer@163.com<白茶清欢> // // Date : 17:10 2022/5/15 -func WithBatchEnd(data map[string]interface{}) SetOption { +func WithBatchEnd(data map[string]any) SetOption { return func(o *Option) { if nil == o.End { - o.End = make(map[string]interface{}) + o.End = make(map[string]any) } for field, value := range data { o.End[field] = value @@ -329,7 +329,7 @@ func WithBatchNotLike(data map[string]string) SetOption { func WithNotEqual[T op_type.BaseType](field string, value T) SetOption { return func(o *Option) { if nil == o.NotEqual { - o.NotEqual = make(map[string]interface{}) + o.NotEqual = make(map[string]any) } o.NotEqual[field] = value } @@ -343,7 +343,7 @@ func WithNotEqual[T op_type.BaseType](field string, value T) SetOption { func WithBatchNotEqual[T op_type.BaseType](data map[string]T) SetOption { return func(o *Option) { if nil == o.NotEqual { - o.NotEqual = make(map[string]interface{}) + o.NotEqual = make(map[string]any) } for field, value := range data { o.NotEqual[field] = value diff --git a/sql2go/dao_tpl.tpl b/sql2go/dao_tpl.tpl index be7f268..ede3a26 100644 --- a/sql2go/dao_tpl.tpl +++ b/sql2go/dao_tpl.tpl @@ -36,9 +36,9 @@ func ({DAO_RECEIVER} *{DATA_STRUCT_DAO}) GetDetailBy{PRIMARY_KEY}(dbInstance *go } // GetList 获取数据列表 -func ({DAO_RECEIVER} *{DATA_STRUCT_DAO}) GetList(dbInstance *gorm.DB, condition map[string]interface{}, limit int, offset int) ([]{DATA_STRUCT_NAME}, error) { +func ({DAO_RECEIVER} *{DATA_STRUCT_DAO}) GetList(dbInstance *gorm.DB, condition map[string]any, limit int, offset int) ([]{DATA_STRUCT_NAME}, error) { if nil == condition { - condition = make(map[string]interface{}) + condition = make(map[string]any) } var ( err error diff --git a/sql2go/define.go b/sql2go/define.go index 6c08512..b89a632 100644 --- a/sql2go/define.go +++ b/sql2go/define.go @@ -90,9 +90,9 @@ func ({DAO_RECEIVER} *{DATA_STRUCT_DAO}) GetDetailBy{PRIMARY_KEY}(dbInstance *go } // GetList 获取数据列表 -func ({DAO_RECEIVER} *{DATA_STRUCT_DAO}) GetList(dbInstance *gorm.DB, condition map[string]interface{}, limit int, offset int) ([]{DATA_STRUCT_NAME}, error) { +func ({DAO_RECEIVER} *{DATA_STRUCT_DAO}) GetList(dbInstance *gorm.DB, condition map[string]any, limit int, offset int) ([]{DATA_STRUCT_NAME}, error) { if nil == condition { - condition = make(map[string]interface{}) + condition = make(map[string]any) } var ( err error diff --git a/sql2go/go_test.go b/sql2go/go_test.go index cd06500..7e8662e 100644 --- a/sql2go/go_test.go +++ b/sql2go/go_test.go @@ -47,9 +47,9 @@ func (ad *AppDao) GetDetailByID(dbInstance *gorm.DB, ID int64) (*App, error) { } // GetList 获取数据列表 -func (ad *AppDao) GetList(dbInstance *gorm.DB, condition map[string]interface{}, limit int, offset int) ([]App, error) { +func (ad *AppDao) GetList(dbInstance *gorm.DB, condition map[string]any, limit int, offset int) ([]App, error) { if nil == condition { - condition = make(map[string]interface{}) + condition = make(map[string]any) } var ( err error diff --git a/system.go b/system.go index 790c4a5..ae9cecd 100644 --- a/system.go +++ b/system.go @@ -85,7 +85,7 @@ func (sd *SystemDao) GetTableList(dbInstance *gorm.DB) ([]string, error) { func (sd *SystemDao) GetCreateTableSQL(dbInstance *gorm.DB, table string) (string, error) { var ( err error - result map[string]interface{} + result map[string]any ) if err = dbInstance.Raw("SHOW CREATE TABLE `" + table + "`").Scan(&result).Error; nil != err { @@ -152,6 +152,6 @@ func (sd *SystemDao) CreateTable(dbInstance *gorm.DB, createTableSql string) err // Author : go_developer@163.com<白茶清欢> // // Date : 16:35 2023/9/30 -func (sd *SystemDao) ExecuteSql(dbInstance *gorm.DB, anySql string, value ...interface{}) error { +func (sd *SystemDao) ExecuteSql(dbInstance *gorm.DB, anySql string, value ...any) error { return dbInstance.Exec(anySql, value...).Error }