Fix regression in db.Not introduced in 940358e.

This commit is contained in:
Tsubasa Munekata 2024-02-22 17:38:03 +09:00
parent d81ae6f701
commit 72a2252049
No known key found for this signature in database
GPG Key ID: D3E6F3430F283A7C
2 changed files with 12 additions and 10 deletions

View File

@ -153,11 +153,6 @@ func Not(exprs ...Expression) Expression {
if len(exprs) == 0 {
return nil
}
if len(exprs) == 1 {
if andCondition, ok := exprs[0].(AndConditions); ok {
exprs = andCondition.Exprs
}
}
return NotConditions{Exprs: exprs}
}

View File

@ -105,6 +105,13 @@ func TestWhere(t *testing.T) {
"SELECT * FROM `users` WHERE (`users`.`id` <> ? AND NOT `score` <= ?)",
[]interface{}{"1", 100},
},
{
[]clause.Interface{clause.Select{}, clause.From{}, clause.Where{
Exprs: []clause.Expression{clause.Not(clause.And(clause.Eq{Column: clause.PrimaryColumn, Value: "1"}, clause.Expr{SQL: "`score` <= ?", Vars: []interface{}{100}, WithoutParentheses: false}))},
}},
"SELECT * FROM `users` WHERE NOT (`users`.`id` = ? AND `score` <= ?)",
[]interface{}{"1", 100},
},
}
for idx, result := range results {