Skip to content

Commit

Permalink
feat: Add support for $eq query constraint in LiveQuery (#8614)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Jun 8, 2023
1 parent b01d4f0 commit 656d673
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/QueryTools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 5 additions & 0 deletions src/LiveQuery/QueryTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 656d673

Please sign in to comment.