Skip to content

Commit

Permalink
测试新WhereOr
Browse files Browse the repository at this point in the history
  • Loading branch information
tobycroft committed Oct 25, 2022
1 parent 13a3a25 commit c9fce88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion builder_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,19 @@ func (b *BuilderDefault) parseWhere(ormApi IOrm) (string, error) {
for _, arr := range whereArrs {
whereArr = append(whereArr, " ("+strings.Join(arr, " "+"and"+" ")+")")
}
where = append(where, condition+" ("+strings.Join(whereArr, " "+condition+" ")+")")
switch condition {
case "andor":
where = append(where, "and ("+strings.Join(whereArr, " or ")+")")
break

case "orand":
where = append(where, "or ("+strings.Join(whereArr, " and ")+")")
break

default:
where = append(where, condition+" ("+strings.Join(whereArr, " "+condition+" ")+")")
break
}
}
break

Expand Down
11 changes: 11 additions & 0 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ func (dba *Orm) Where(args ...interface{}) IOrm {
return dba
}

// Where : query or execute where condition, the relation is and
func (dba *Orm) WhereOr(args interface{}) IOrm {
// 如果只传入一个参数, 则可能是字符串、一维对象、二维数组
// 重新组合为长度为3的数组, 第一项为关系(and/or), 第二项为具体传入的参数 []interface{}
w := []interface{}{"andor", args}

dba.where = append(dba.where, w)

return dba
}

// Where : query or execute where condition, the relation is and
func (dba *Orm) OrWhere(args ...interface{}) IOrm {
// 如果只传入一个参数, 则可能是字符串、一维对象、二维数组
Expand Down

0 comments on commit c9fce88

Please sign in to comment.