feat: sql 构建支持 FOR UPDATE
This commit is contained in:
8
base.go
8
base.go
@ -7,9 +7,11 @@ package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/database/define"
|
||||
"gorm.io/gorm"
|
||||
"reflect"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// BaseDao 基础dao层
|
||||
@ -283,6 +285,10 @@ func (b *BaseDao) setTxCondition(inputTx *gorm.DB, optionFuncList ...define.SetO
|
||||
tx = tx.Where(o.Where)
|
||||
}
|
||||
|
||||
if o.ForUpdate {
|
||||
tx = tx.Clauses(clause.Locking{Strength: "UPDATE"})
|
||||
}
|
||||
|
||||
// between
|
||||
for field, betweenVal := range o.Between {
|
||||
tx = tx.Where("`"+field+"` BETWEEN ? AND ?", betweenVal[0], betweenVal[1])
|
||||
|
Reference in New Issue
Block a user