diff --git a/base.go b/base.go index 491bf61..0bb19e9 100644 --- a/base.go +++ b/base.go @@ -17,7 +17,7 @@ import ( // // Date : 14:13 2023/2/9 type BaseDao struct { - TableName string // 继承BaseDao,需要指定表名,后续调用不用传递表名进来 + TableName string // 继承BaseDao,需要指定表名,后续调用不用传递表名进来,如果分表了,使用SetOption设置表名, 这里的优先级更高 } // Create 创建新的数据 @@ -25,8 +25,16 @@ type BaseDao struct { // Author : go_developer@163.com<白茶清欢> // // Date : 8:06 下午 2021/8/8 -func (b *BaseDao) Create(dbInstance *gorm.DB, data interface{}) error { - return dbInstance.Create(data).Error +func (b *BaseDao) Create(dbInstance *gorm.DB, data interface{}, optionList ...SetOption) error { + o := &Option{} + for _, itemFunc := range optionList { + itemFunc(o) + } + tableName := b.TableName + if len(o.Table) > 0 { + tableName = o.Table + } + return dbInstance.Table(tableName).Create(data).Error } // Update 更新数据