Skip to content

Commit 057fc40

Browse files
authored
Postgres: Query notEqualTo GeoPoint (#5549)
* Postgres: Query notEqualTo GeoPoint * remove templated strings
1 parent fa97df5 commit 057fc40

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

spec/ParseGeoPoint.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,4 +771,24 @@ describe('Parse.GeoPoint testing', () => {
771771

772772
equal(count, 2);
773773
});
774+
775+
it('fails to fetch geopoints that are specifically not at (0,0)', async () => {
776+
const tmp = new TestObject({
777+
location: new Parse.GeoPoint({ latitude: 0, longitude: 0 }),
778+
});
779+
const tmp2 = new TestObject({
780+
location: new Parse.GeoPoint({
781+
latitude: 49.2577142,
782+
longitude: -123.1941149,
783+
}),
784+
});
785+
await Parse.Object.saveAll([tmp, tmp2]);
786+
const query = new Parse.Query(TestObject);
787+
query.notEqualTo(
788+
'location',
789+
new Parse.GeoPoint({ latitude: 0, longitude: 0 })
790+
);
791+
const results = await query.find();
792+
expect(results.length).toEqual(1);
793+
});
774794
});

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,27 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
360360
continue;
361361
} else {
362362
// if not null, we need to manually exclude null
363-
patterns.push(
364-
`($${index}:name <> $${index + 1} OR $${index}:name IS NULL)`
365-
);
363+
if (fieldValue.$ne.__type === 'GeoPoint') {
364+
patterns.push(
365+
`($${index}:name <> POINT($${index + 1}, $${index +
366+
2}) OR $${index}:name IS NULL)`
367+
);
368+
} else {
369+
patterns.push(
370+
`($${index}:name <> $${index + 1} OR $${index}:name IS NULL)`
371+
);
372+
}
366373
}
367374
}
368-
369-
// TODO: support arrays
370-
values.push(fieldName, fieldValue.$ne);
371-
index += 2;
375+
if (fieldValue.$ne.__type === 'GeoPoint') {
376+
const point = fieldValue.$ne;
377+
values.push(fieldName, point.longitude, point.latitude);
378+
index += 3;
379+
} else {
380+
// TODO: support arrays
381+
values.push(fieldName, fieldValue.$ne);
382+
index += 2;
383+
}
372384
}
373385
if (fieldValue.$eq !== undefined) {
374386
if (fieldValue.$eq === null) {
@@ -730,15 +742,7 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
730742
}
731743

732744
if (fieldValue.__type === 'GeoPoint') {
733-
patterns.push(
734-
'$' +
735-
index +
736-
':name ~= POINT($' +
737-
(index + 1) +
738-
', $' +
739-
(index + 2) +
740-
')'
741-
);
745+
patterns.push(`$${index}:name ~= POINT($${index + 1}, $${index + 2})`);
742746
values.push(fieldName, fieldValue.longitude, fieldValue.latitude);
743747
index += 3;
744748
}

0 commit comments

Comments
 (0)