mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
dialect/sql: make sql.In() with empty args fallback to False() (#2735)
* dialect/sql/builder: make sql.In() with empty args fallback to False() * fix indent * added comment * remove the equilvalent logic in the codegen side * comment fix, run go generate
This commit is contained in:
@@ -1535,8 +1535,10 @@ func In(col string, args ...interface{}) *Predicate {
|
||||
|
||||
// In appends the `IN` predicate.
|
||||
func (p *Predicate) In(col string, args ...interface{}) *Predicate {
|
||||
// if no arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(args) == 0 {
|
||||
return p
|
||||
return p.False()
|
||||
}
|
||||
return p.Append(func(b *Builder) {
|
||||
b.Ident(col).WriteOp(OpIn)
|
||||
|
||||
@@ -2004,6 +2004,14 @@ func TestReusePredicates(t *testing.T) {
|
||||
wantQuery: `SELECT * FROM "users" WHERE "a" = $1 OR "b" = $2`,
|
||||
wantArgs: []interface{}{"a", "b"},
|
||||
},
|
||||
{
|
||||
p: Or(
|
||||
EQ("a", "a"),
|
||||
In("b"),
|
||||
),
|
||||
wantQuery: `SELECT * FROM "users" WHERE "a" = $1 OR FALSE`,
|
||||
wantArgs: []interface{}{"a"},
|
||||
},
|
||||
{
|
||||
p: And(
|
||||
EQ("active", true),
|
||||
|
||||
Reference in New Issue
Block a user