Skip to content

Commit b692e85

Browse files
dplewisflovilmart
authored andcommitted
fix(Postgres): Support for GeoPoint equality query (#3875)
* Postgres doesn't support this query type yet * removing conflict * near test * remove trailing space
1 parent bd2ea87 commit b692e85

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

spec/ParseGeoPoint.spec.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('Parse.GeoPoint testing', () => {
5353
obj.set('name', 'Zhoul')
5454
obj.save(null, {
5555
success: (obj) => {
56-
console.log(obj);
5756
Parse.Cloud.httpRequest({
5857
url: 'http://localhost:8378/1/classes/TestObject/' + obj.id,
5958
headers: {
@@ -316,6 +315,21 @@ describe('Parse.GeoPoint testing', () => {
316315
});
317316
});
318317

318+
it('returns nearest location', (done) => {
319+
makeSomeGeoPoints(function() {
320+
var sfo = new Parse.GeoPoint(37.6189722, -122.3748889);
321+
var query = new Parse.Query(TestObject);
322+
query.near('location', sfo);
323+
query.find({
324+
success: function(results) {
325+
equal(results[0].get('name'), 'San Francisco');
326+
equal(results[1].get('name'), 'Sacramento');
327+
done();
328+
}
329+
});
330+
});
331+
});
332+
319333
it('works with geobox queries', (done) => {
320334
var inSF = new Parse.GeoPoint(37.75, -122.4);
321335
var southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
@@ -376,6 +390,23 @@ describe('Parse.GeoPoint testing', () => {
376390
});
377391
});
378392

393+
it('equalTo geopoint', (done) => {
394+
var point = new Parse.GeoPoint(44.0, -11.0);
395+
var obj = new TestObject();
396+
obj.set('location', point);
397+
obj.save().then(() => {
398+
const query = new Parse.Query(TestObject);
399+
query.equalTo('location', point);
400+
return query.find();
401+
}).then((results) => {
402+
equal(results.length, 1);
403+
const loc = results[0].get('location');
404+
equal(loc.latitude, point.latitude);
405+
equal(loc.longitude, point.longitude);
406+
done();
407+
});
408+
});
409+
379410
it('supports withinPolygon', (done) => {
380411
const point1 = new Parse.GeoPoint(1.5, 1.5);
381412
const point2 = new Parse.GeoPoint(2, 8);

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ const buildWhereClause = ({ schema, query, index }) => {
402402
index += 2;
403403
}
404404

405+
if (fieldValue.__type === 'GeoPoint') {
406+
patterns.push('$' + index + ':name ~= POINT($' + (index + 1) + ', $' + (index + 2) + ')');
407+
values.push(fieldName, fieldValue.longitude, fieldValue.latitude);
408+
index += 3;
409+
}
410+
405411
Object.keys(ParseToPosgresComparator).forEach(cmp => {
406412
if (fieldValue[cmp]) {
407413
const pgComparator = ParseToPosgresComparator[cmp];

0 commit comments

Comments
 (0)