mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
dialect/sql/builder: make sql.NotIn() with empty args fallback to NOT FALSE (#2757)
* dialect/sql/builder: make sql.NotIn() with empty args fallback to False() This is basically the identical change to #2735, but for NotIn(). This bug currently prevents anyone using NotIn() from upgrading from v0.10.x to v0.11.x * Update go.sum untidy * feedback
This commit is contained in:
@@ -1587,8 +1587,10 @@ func NotIn(col string, args ...interface{}) *Predicate {
|
||||
|
||||
// NotIn appends the `Not IN` predicate.
|
||||
func (p *Predicate) NotIn(col string, args ...interface{}) *Predicate {
|
||||
// If no arguments were provided, append the NOT FALSE constant, since
|
||||
// we cannot apply "NOT IN ()". This will make this predicate truthy.
|
||||
if len(args) == 0 {
|
||||
return p
|
||||
return Not(p.False())
|
||||
}
|
||||
return p.Append(func(b *Builder) {
|
||||
b.Ident(col).WriteOp(OpNotIn)
|
||||
|
||||
@@ -635,6 +635,16 @@ func TestBuilder(t *testing.T) {
|
||||
wantQuery: `DELETE FROM "users" WHERE "parent_id" IS NULL AND "name" NOT IN ($1, $2)`,
|
||||
wantArgs: []interface{}{"foo", "bar"},
|
||||
},
|
||||
{
|
||||
input: Delete("users").
|
||||
Where(And(IsNull("parent_id"), In("name"))),
|
||||
wantQuery: "DELETE FROM `users` WHERE `parent_id` IS NULL AND FALSE",
|
||||
},
|
||||
{
|
||||
input: Delete("users").
|
||||
Where(And(IsNull("parent_id"), NotIn("name"))),
|
||||
wantQuery: "DELETE FROM `users` WHERE `parent_id` IS NULL AND (NOT (FALSE))",
|
||||
},
|
||||
{
|
||||
input: Delete("users").
|
||||
Where(And(False(), False())),
|
||||
|
||||
Reference in New Issue
Block a user