支持OR语句

This commit is contained in:
2022-07-23 20:11:51 +08:00
parent 2fb098b469
commit 2e2846ddb0
2 changed files with 39 additions and 0 deletions

14
base.go
View File

@ -157,5 +157,19 @@ func (b *BaseDao) setTxCondition(tx *gorm.DB, table string, optionFuncList ...Se
tx = tx.Where(field+" < ?", value)
}
}
// or 语句
if nil != o.OR {
expression := ""
valList := make([]interface{}, 0)
for _, o := range o.OR {
if len(expression) > 0 {
expression = expression + " OR "
}
expression = expression + " " + o.Express
valList = append(valList, o.Value)
}
tx = tx.Where(expression, valList...)
}
return tx
}