Skip to content

Commit

Permalink
Always return nil for empty values (#11)
Browse files Browse the repository at this point in the history
Don't sometimes return []any{} instead. Keep the API consistent.
  • Loading branch information
erikdubbelboer authored Jun 15, 2024
1 parent eb8d8d6 commit bd01a75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion filter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ func (c *Converter) Convert(query []byte, startAtParameterIndex int) (conditions
return "", nil, fmt.Errorf("startAtParameterIndex must be greater than 0")
}

if len(query) == 0 {
return c.emptyCondition, nil, nil
}

var mongoFilter map[string]any
err = json.Unmarshal(query, &mongoFilter)
if err != nil {
return "", nil, err
}

if len(mongoFilter) == 0 {
return c.emptyCondition, []any{}, nil
return c.emptyCondition, nil, nil
}

conditions, values, err = c.convertFilter(mongoFilter, startAtParameterIndex)
Expand Down
2 changes: 1 addition & 1 deletion filter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestConverter_Convert(t *testing.T) {
nil,
`{}`,
`FALSE`,
[]any{},
nil,
nil,
}, {
"empty or conditions",
Expand Down

0 comments on commit bd01a75

Please sign in to comment.