Postgres: Query notEqualTo GeoPoint (#5549)
* Postgres: Query notEqualTo GeoPoint * remove templated strings
This commit is contained in:
@@ -771,4 +771,24 @@ describe('Parse.GeoPoint testing', () => {
|
|||||||
|
|
||||||
equal(count, 2);
|
equal(count, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('fails to fetch geopoints that are specifically not at (0,0)', async () => {
|
||||||
|
const tmp = new TestObject({
|
||||||
|
location: new Parse.GeoPoint({ latitude: 0, longitude: 0 }),
|
||||||
|
});
|
||||||
|
const tmp2 = new TestObject({
|
||||||
|
location: new Parse.GeoPoint({
|
||||||
|
latitude: 49.2577142,
|
||||||
|
longitude: -123.1941149,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
await Parse.Object.saveAll([tmp, tmp2]);
|
||||||
|
const query = new Parse.Query(TestObject);
|
||||||
|
query.notEqualTo(
|
||||||
|
'location',
|
||||||
|
new Parse.GeoPoint({ latitude: 0, longitude: 0 })
|
||||||
|
);
|
||||||
|
const results = await query.find();
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -360,15 +360,27 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// if not null, we need to manually exclude null
|
// if not null, we need to manually exclude null
|
||||||
patterns.push(
|
if (fieldValue.$ne.__type === 'GeoPoint') {
|
||||||
`($${index}:name <> $${index + 1} OR $${index}:name IS NULL)`
|
patterns.push(
|
||||||
);
|
`($${index}:name <> POINT($${index + 1}, $${index +
|
||||||
|
2}) OR $${index}:name IS NULL)`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
patterns.push(
|
||||||
|
`($${index}:name <> $${index + 1} OR $${index}:name IS NULL)`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (fieldValue.$ne.__type === 'GeoPoint') {
|
||||||
// TODO: support arrays
|
const point = fieldValue.$ne;
|
||||||
values.push(fieldName, fieldValue.$ne);
|
values.push(fieldName, point.longitude, point.latitude);
|
||||||
index += 2;
|
index += 3;
|
||||||
|
} else {
|
||||||
|
// TODO: support arrays
|
||||||
|
values.push(fieldName, fieldValue.$ne);
|
||||||
|
index += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fieldValue.$eq !== undefined) {
|
if (fieldValue.$eq !== undefined) {
|
||||||
if (fieldValue.$eq === null) {
|
if (fieldValue.$eq === null) {
|
||||||
@@ -730,15 +742,7 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fieldValue.__type === 'GeoPoint') {
|
if (fieldValue.__type === 'GeoPoint') {
|
||||||
patterns.push(
|
patterns.push(`$${index}:name ~= POINT($${index + 1}, $${index + 2})`);
|
||||||
'$' +
|
|
||||||
index +
|
|
||||||
':name ~= POINT($' +
|
|
||||||
(index + 1) +
|
|
||||||
', $' +
|
|
||||||
(index + 2) +
|
|
||||||
')'
|
|
||||||
);
|
|
||||||
values.push(fieldName, fieldValue.longitude, fieldValue.latitude);
|
values.push(fieldName, fieldValue.longitude, fieldValue.latitude);
|
||||||
index += 3;
|
index += 3;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user