From cf3d37e3a0e7e55657e6fc48dc9c911810b3caa3 Mon Sep 17 00:00:00 2001 From: Corey Date: Fri, 2 Jun 2023 09:42:09 -0400 Subject: [PATCH 1/2] feat: Support eq query constraint in LiveQuery Signed-off-by: Corey --- src/LiveQuery/QueryTools.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/LiveQuery/QueryTools.js b/src/LiveQuery/QueryTools.js index 50d8d3394a..1607278f46 100644 --- a/src/LiveQuery/QueryTools.js +++ b/src/LiveQuery/QueryTools.js @@ -247,6 +247,11 @@ function matchesKeyConstraints(object, key, constraints) { return false; } break; + case '$eq': + if (!equalObjects(object[key], compareTo)) { + return false; + } + break; case '$ne': if (equalObjects(object[key], compareTo)) { return false; From 4cd4e2295e2b8268baaaa794a8138d142b71e65a Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Mon, 5 Jun 2023 10:34:02 -0400 Subject: [PATCH 2/2] add tests" git push ` ` --- spec/QueryTools.spec.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index dbd3c9a5d3..8dbda98b0a 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -125,6 +125,35 @@ describe('matchesQuery', function () { expect(matchesQuery(obj, q)).toBe(false); }); + it('matches queries with eq constraint', function () { + const obj = { + objectId: 'Person2', + score: 12, + name: 'Tom', + }; + + const q1 = { + objectId: { + $eq: 'Person2', + }, + }; + + const q2 = { + score: { + $eq: 12, + }, + }; + + const q3 = { + name: { + $eq: 'Tom', + }, + }; + expect(matchesQuery(obj, q1)).toBe(true); + expect(matchesQuery(obj, q2)).toBe(true); + expect(matchesQuery(obj, q3)).toBe(true); + }); + it('matches on equality queries', function () { const day = new Date(); const location = new Parse.GeoPoint({