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);
|
||||
});
|
||||
|
||||
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;
|
||||
} else {
|
||||
// if not null, we need to manually exclude null
|
||||
patterns.push(
|
||||
`($${index}:name <> $${index + 1} OR $${index}:name IS NULL)`
|
||||
);
|
||||
if (fieldValue.$ne.__type === 'GeoPoint') {
|
||||
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)`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: support arrays
|
||||
values.push(fieldName, fieldValue.$ne);
|
||||
index += 2;
|
||||
if (fieldValue.$ne.__type === 'GeoPoint') {
|
||||
const point = fieldValue.$ne;
|
||||
values.push(fieldName, point.longitude, point.latitude);
|
||||
index += 3;
|
||||
} else {
|
||||
// TODO: support arrays
|
||||
values.push(fieldName, fieldValue.$ne);
|
||||
index += 2;
|
||||
}
|
||||
}
|
||||
if (fieldValue.$eq !== undefined) {
|
||||
if (fieldValue.$eq === null) {
|
||||
@@ -730,15 +742,7 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
|
||||
}
|
||||
|
||||
if (fieldValue.__type === 'GeoPoint') {
|
||||
patterns.push(
|
||||
'$' +
|
||||
index +
|
||||
':name ~= POINT($' +
|
||||
(index + 1) +
|
||||
', $' +
|
||||
(index + 2) +
|
||||
')'
|
||||
);
|
||||
patterns.push(`$${index}:name ~= POINT($${index + 1}, $${index + 2})`);
|
||||
values.push(fieldName, fieldValue.longitude, fieldValue.latitude);
|
||||
index += 3;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user