Skip to content

Postgres doesn't support this query type yet #3875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion spec/ParseGeoPoint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe('Parse.GeoPoint testing', () => {
obj.set('name', 'Zhoul')
obj.save(null, {
success: (obj) => {
console.log(obj);
Parse.Cloud.httpRequest({
url: 'http://localhost:8378/1/classes/TestObject/' + obj.id,
headers: {
Expand Down Expand Up @@ -316,6 +315,21 @@ describe('Parse.GeoPoint testing', () => {
});
});

it('returns nearest location', (done) => {
makeSomeGeoPoints(function() {
var sfo = new Parse.GeoPoint(37.6189722, -122.3748889);
var query = new Parse.Query(TestObject);
query.near('location', sfo);
query.find({
success: function(results) {
equal(results[0].get('name'), 'San Francisco');
equal(results[1].get('name'), 'Sacramento');
done();
}
});
});
});

it('works with geobox queries', (done) => {
var inSF = new Parse.GeoPoint(37.75, -122.4);
var southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
Expand Down Expand Up @@ -376,6 +390,23 @@ describe('Parse.GeoPoint testing', () => {
});
});

it('equalTo geopoint', (done) => {
var point = new Parse.GeoPoint(44.0, -11.0);
var obj = new TestObject();
obj.set('location', point);
obj.save().then(() => {
const query = new Parse.Query(TestObject);
query.equalTo('location', point);
return query.find();
}).then((results) => {
equal(results.length, 1);
const loc = results[0].get('location');
equal(loc.latitude, point.latitude);
equal(loc.longitude, point.longitude);
done();
});
});

it('supports withinPolygon', (done) => {
const point1 = new Parse.GeoPoint(1.5, 1.5);
const point2 = new Parse.GeoPoint(2, 8);
Expand Down
6 changes: 6 additions & 0 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ const buildWhereClause = ({ schema, query, index }) => {
index += 2;
}

if (fieldValue.__type === 'GeoPoint') {
patterns.push('$' + index + ':name ~= POINT($' + (index + 1) + ', $' + (index + 2) + ')');
values.push(fieldName, fieldValue.longitude, fieldValue.latitude);
index += 3;
}

Object.keys(ParseToPosgresComparator).forEach(cmp => {
if (fieldValue[cmp]) {
const pgComparator = ParseToPosgresComparator[cmp];
Expand Down