Skip to content

Commit

Permalink
fix: ignore nil query (#6021)
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Feb 2, 2023
1 parent 4d6b70e commit e1f46eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) []
conds := make([]clause.Expression, 0, 4)
args = append([]interface{}{query}, args...)
for idx, arg := range args {
if arg == nil {
continue
}
if valuer, ok := arg.(driver.Valuer); ok {
arg, _ = valuer.Value()
}
Expand Down
7 changes: 7 additions & 0 deletions statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func TestWhereCloneCorruption(t *testing.T) {
}
}

func TestNilCondition(t *testing.T) {
s := new(Statement)
if len(s.BuildCondition(nil)) != 0 {
t.Errorf("Nil condition should be empty")
}
}

func TestNameMatcher(t *testing.T) {
for k, v := range map[string][]string{
"table.name": {"table", "name"},
Expand Down

0 comments on commit e1f46eb

Please sign in to comment.