修复查询语句实例服用,前后条件互相干扰问题
This commit is contained in:
11
base.go
11
base.go
@ -92,6 +92,8 @@ func (b *BaseDao) ListAndTotal(dbInstance *gorm.DB, listRes any, disableTotal bo
|
||||
// 禁用查询总数
|
||||
return int64(reflect.ValueOf(listRes).Elem().Len()), nil
|
||||
}
|
||||
optionFuncList = append(optionFuncList, WithClearLimit())
|
||||
dbInstance = b.setTxCondition(dbInstance, optionFuncList...)
|
||||
if err = dbInstance.Count(&cnt).Error; nil != err {
|
||||
return 0, err
|
||||
}
|
||||
@ -149,6 +151,7 @@ func (b *BaseDao) IsNotFound(err error) bool {
|
||||
//
|
||||
// Date : 8:25 下午 2021/8/8
|
||||
func (b *BaseDao) Count(dbInstance *gorm.DB, optionFuncList ...define.SetOption) (int64, error) {
|
||||
optionFuncList = append(optionFuncList, WithClearLimit())
|
||||
dbInstance = b.setTxCondition(dbInstance, optionFuncList...)
|
||||
var cnt int64
|
||||
return cnt, dbInstance.Count(&cnt).Error
|
||||
@ -203,14 +206,18 @@ func (b *BaseDao) Rollback(db *gorm.DB) error {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:38 2022/5/15
|
||||
func (b *BaseDao) setTxCondition(tx *gorm.DB, optionFuncList ...define.SetOption) *gorm.DB {
|
||||
|
||||
func (b *BaseDao) setTxCondition(inputTx *gorm.DB, optionFuncList ...define.SetOption) *gorm.DB {
|
||||
// 构建查询条件
|
||||
o := &define.Option{}
|
||||
for _, fn := range optionFuncList {
|
||||
fn(o)
|
||||
}
|
||||
|
||||
tx := inputTx.Session(&gorm.Session{
|
||||
NewDB: true,
|
||||
Initialized: true,
|
||||
})
|
||||
|
||||
// 指定查询的表
|
||||
if len(o.Table) > 0 {
|
||||
tx = tx.Table(o.Table)
|
||||
|
Reference in New Issue
Block a user