From 84224b7deb301acffb21cbc3df9da1a29c1d91db Mon Sep 17 00:00:00 2001 From: chyroc Date: Thu, 2 Feb 2023 17:37:33 +0800 Subject: [PATCH] fix: ignore nil query --- statement.go | 3 +++ statement_test.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/statement.go b/statement.go index b99648fa..08165293 100644 --- a/statement.go +++ b/statement.go @@ -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() } diff --git a/statement_test.go b/statement_test.go index 761daf37..648bc875 100644 --- a/statement_test.go +++ b/statement_test.go @@ -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"},