Skip to content

Commit 988cab7

Browse files
committed
Add support for Point datatype
1 parent 7fb89c8 commit 988cab7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/resultSet.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const ResultSetValueTypes = {
3838
VALUE_NODE: 8,
3939
VALUE_PATH: 9,
4040
VALUE_MAP: 10,
41+
VALUE_POINT: 11,
4142
};
4243

4344
/**
@@ -278,6 +279,20 @@ class ResultSet {
278279
return m;
279280
}
280281

282+
/**
283+
* Parse a raw Point representation into a lat-lon Map object.
284+
* @async
285+
* @param {object[]} rawPoint 2-valued lat-lon array representation
286+
* @returns {Promise<object>} Map object with latitude and longitude keys.
287+
*/
288+
async parsePoint(rawPoint) {
289+
let m = {};
290+
m["latitude"] = Number(rawPoint[0])
291+
m["longitude"] = Number(rawPoint[1])
292+
293+
return m;
294+
}
295+
281296
/**
282297
* Parse a raw value into its actual value.
283298
* @async
@@ -326,6 +341,10 @@ class ResultSet {
326341
scalar = await this.parseMap(value);
327342
break;
328343

344+
case ResultSetValueTypes.VALUE_POINT:
345+
scalar = await this.parsePoint(value);
346+
break;
347+
329348
case ResultSetValueTypes.VALUE_UNKNOWN:
330349
console.log("Unknown scalar type\n");
331350
break;

test/redisGraphAPITest.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ describe("RedisGraphAPI Test", () => {
305305
assert.ok(!resultSet.hasNext());
306306
});
307307

308+
it("test point", async () => {
309+
// return point value
310+
let resultSet = await api.query("RETURN point({latitude: 32, longitude: 34})");
311+
assert.equal(resultSet.size(), 1);
312+
assert.ok(resultSet.hasNext());
313+
314+
let record = resultSet.next();
315+
let expected = {latitude: 32, longitude: 34}
316+
assert.deepStrictEqual(expected, record.get(0));
317+
assert.ok(!resultSet.hasNext());
318+
});
319+
308320
it("test multi thread", async () => {
309321
await api.query("CREATE (:person {name:'roi', age:34})");
310322
var promises = [];

0 commit comments

Comments
 (0)