feat: sql 构建支持 FOR UPDATE

This commit is contained in:
2025-10-11 18:10:29 +08:00
parent 4acb528533
commit cb3d32c360
3 changed files with 19 additions and 120 deletions

View File

@ -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])