mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
update gdb.Model.Where, orverwrite args if multiple calls Where function
This commit is contained in:
@ -66,6 +66,7 @@ func formatCondition(where interface{}, args []interface{}) (newWhere string, ne
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
newArgs = append(newArgs, rv.Index(i).Interface())
|
||||
}
|
||||
// counter用于匹配该参数的位置(与index对应)
|
||||
counter := 0
|
||||
newWhere, _ = gregex.ReplaceStringFunc(`\?`, newWhere, func(s string) string {
|
||||
counter++
|
||||
|
||||
@ -136,12 +136,13 @@ func (md *Model) Filter() (*Model) {
|
||||
return model
|
||||
}
|
||||
|
||||
// 链式操作,condition,支持string & gdb.Map
|
||||
// 链式操作,condition,支持string & gdb.Map.
|
||||
// 注意,多个Where调用时,会相互覆盖,只有最后一个Where语句生效。
|
||||
func (md *Model) Where(where interface{}, args ...interface{}) (*Model) {
|
||||
model := md.getModel()
|
||||
newWhere, newArgs := formatCondition(where, args)
|
||||
model.where = newWhere
|
||||
model.whereArgs = append(model.whereArgs, newArgs...)
|
||||
model.whereArgs = newArgs
|
||||
// 支持 Where("uid", 1)这种格式
|
||||
if len(args) == 1 && strings.Index(model.where , "?") < 0 {
|
||||
model.where += "=?"
|
||||
|
||||
Reference in New Issue
Block a user