refactor Or

This commit is contained in:
Lunny Xiao 2021-06-12 21:16:52 +08:00
parent 25c5dec5fd
commit d59a38de83
1 changed files with 8 additions and 6 deletions

View File

@ -234,23 +234,25 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
// Or add Where & Or statement
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
switch query.(type) {
switch qr := query.(type) {
case string:
cond := builder.Expr(query.(string), args...)
cond := builder.Expr(qr, args...)
statement.cond = statement.cond.Or(cond)
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)
case builder.Cond:
cond := query.(builder.Cond)
statement.cond = statement.cond.Or(cond)
statement.cond = statement.cond.Or(qr)
for _, v := range args {
if vv, ok := v.(builder.Cond); ok {
statement.cond = statement.cond.Or(vv)
}
}
default:
// TODO: not support condition type
statement.LastError = ErrConditionType
}
return statement
}