Skip to content

Commit bd01a75

Browse files
Always return nil for empty values (#11)
Don't sometimes return []any{} instead. Keep the API consistent.
1 parent eb8d8d6 commit bd01a75

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

filter/converter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ func (c *Converter) Convert(query []byte, startAtParameterIndex int) (conditions
5353
return "", nil, fmt.Errorf("startAtParameterIndex must be greater than 0")
5454
}
5555

56+
if len(query) == 0 {
57+
return c.emptyCondition, nil, nil
58+
}
59+
5660
var mongoFilter map[string]any
5761
err = json.Unmarshal(query, &mongoFilter)
5862
if err != nil {
5963
return "", nil, err
6064
}
6165

6266
if len(mongoFilter) == 0 {
63-
return c.emptyCondition, []any{}, nil
67+
return c.emptyCondition, nil, nil
6468
}
6569

6670
conditions, values, err = c.convertFilter(mongoFilter, startAtParameterIndex)

filter/converter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestConverter_Convert(t *testing.T) {
198198
nil,
199199
`{}`,
200200
`FALSE`,
201-
[]any{},
201+
nil,
202202
nil,
203203
}, {
204204
"empty or conditions",

0 commit comments

Comments
 (0)