Skip to content

Commit

Permalink
feat(firestore): support "!=" and "not-in" query operators
Browse files Browse the repository at this point in the history
Firestore Version 7.21.0 - September 17, 2020 - introduced support for
the "!=" (NOT_EQUAL) and "not-in" (NOT_IN) query operators:
https://firebase.google.com/support/release-notes/js#version_7210_-_september_17_2020

Query operator documentation:
https://firebase.google.com/docs/firestore/query-data/queries

This patch adds support for these two new operators and adds test
cases for them.
  • Loading branch information
jacksgt committed Nov 14, 2020
1 parent 581bf92 commit 12ca3f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions firestore/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ func TestIntegration_QueryDocuments(t *testing.T) {
}{
{q, wants},
{q.Where("q", ">", 1), wants[2:]},
{q.Where("q", "<", 1), wants[:1]},
{q.Where("q", "==", 1), wants[1:2]},
{q.Where("q", "!=", 0), wants[1:]},
{q.Where("q", ">=", 1), wants[1:]},
{q.Where("q", "<=", 1), wants[:2]},
{q.WherePath([]string{"q"}, ">", 1), wants[2:]},
{q.Offset(1).Limit(1), wants[1:2]},
{q.StartAt(1), wants[1:]},
Expand Down
4 changes: 4 additions & 0 deletions firestore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,12 @@ func (f filter) toProto() (*pb.StructuredQuery_Filter, error) {
op = pb.StructuredQuery_FieldFilter_GREATER_THAN_OR_EQUAL
case "==":
op = pb.StructuredQuery_FieldFilter_EQUAL
case "!=":
op = pb.StructuredQuery_Filter_NOT_EQUAL
case "in":
op = pb.StructuredQuery_FieldFilter_IN
case "not-in":
op = pb.StructuredQuery_Filter_NOT_IN
case "array-contains":
op = pb.StructuredQuery_FieldFilter_ARRAY_CONTAINS
case "array-contains-any":
Expand Down
10 changes: 10 additions & 0 deletions firestore/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,21 @@ func TestQueryToProto(t *testing.T) {
in: q.Where("a", "==", float32(math.NaN())),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "==", math.NaN())},
},
{
desc: `q.Where("a", "!=", NaN)`,
in: q.Where("a", "!=", float32(math.NaN())),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "!=", math.NaN())},
},
{
desc: `q.Where("a", "in", []int{7, 8})`,
in: q.Where("a", "in", []int{7, 8}),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "in", []int{7, 8})},
},
{
desc: `q.Where("a", "not-in", []int{9})`,
in: q.Where("a", "not-in", []int{9}),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "not-in", []int{9})},
},
{
desc: `q.Where("c", "array-contains", 1)`,
in: q.Where("c", "array-contains", 1),
Expand Down

0 comments on commit 12ca3f8

Please sign in to comment.