refactor Or
This commit is contained in:
parent
25c5dec5fd
commit
d59a38de83
|
@ -234,23 +234,25 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
|
||||||
|
|
||||||
// Or add Where & Or statement
|
// Or add Where & Or statement
|
||||||
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
||||||
switch query.(type) {
|
switch qr := query.(type) {
|
||||||
case string:
|
case string:
|
||||||
cond := builder.Expr(query.(string), args...)
|
cond := builder.Expr(qr, args...)
|
||||||
statement.cond = statement.cond.Or(cond)
|
statement.cond = statement.cond.Or(cond)
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
cond := builder.Eq(query.(map[string]interface{}))
|
cond := make(builder.Eq)
|
||||||
|
for k, v := range qr {
|
||||||
|
cond[statement.quote(k)] = v
|
||||||
|
}
|
||||||
statement.cond = statement.cond.Or(cond)
|
statement.cond = statement.cond.Or(cond)
|
||||||
case builder.Cond:
|
case builder.Cond:
|
||||||
cond := query.(builder.Cond)
|
statement.cond = statement.cond.Or(qr)
|
||||||
statement.cond = statement.cond.Or(cond)
|
|
||||||
for _, v := range args {
|
for _, v := range args {
|
||||||
if vv, ok := v.(builder.Cond); ok {
|
if vv, ok := v.(builder.Cond); ok {
|
||||||
statement.cond = statement.cond.Or(vv)
|
statement.cond = statement.cond.Or(vv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// TODO: not support condition type
|
statement.LastError = ErrConditionType
|
||||||
}
|
}
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue