fix(Postgres): Support for GeoPoint equality query (#3875)
* Postgres doesn't support this query type yet * removing conflict * near test * remove trailing space
This commit is contained in:
committed by
Florent Vilmart
parent
bd2ea87c1d
commit
b692e8578d
@@ -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: {
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -402,6 +402,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];
|
||||
|
||||
Reference in New Issue
Block a user