New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dialect/sql/builder: make sql.In() with empty args fallback to False() #2735
Changes from all commits
46c975c
61d1fa8
f1fcc1c
52c502b
298425f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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() | ||||||||||||
Comment on lines
-1539
to
+1541
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks added in f1fcc1c 👍 |
||||||||||||
} | ||||||||||||
return p.Append(func(b *Builder) { | ||||||||||||
b.Ident(col).WriteOp(OpIn) | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,6 @@ in the LICENSE file in the root directory of this source tree. | |
{{- $storage := $.Scope.Storage -}} | ||
func(s *sql.Selector) { | ||
{{- if $op.Variadic }} | ||
// if not arguments were provided, append the FALSE constants, | ||
// since we can't apply "IN ()". This will make this predicate falsy. | ||
if len({{ $arg }}) == 0 { | ||
s.Where(sql.False()) | ||
return | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run |
||
v := make([]interface{}, len({{ $arg }})) | ||
for i := range v { | ||
v[i] = {{ $arg }}[i] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comment, can you please copy the comment from here:
https://github.com/ent/ent/blob/master/entc/gen/template/dialect/sql/predicate.tmpl#L21-L22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also remove this if-statement from the codegen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really agreed, fixed in 52c502b 🙏