Skip to content

Add support for Point datatype #67

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 3 commits into from
Feb 27, 2021
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
25 changes: 25 additions & 0 deletions src/resultSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ResultSetValueTypes = {
VALUE_NODE: 8,
VALUE_PATH: 9,
VALUE_MAP: 10,
VALUE_POINT: 11,
};

/**
Expand Down Expand Up @@ -278,6 +279,19 @@ class ResultSet {
return m;
}

/**
* Parse a raw Point representation into a lat-lon Map object.
* @param {object[]} rawPoint 2-valued lat-lon array representation
* @returns {{ latitude: number, longitude: number }} Map object with latitude and longitude keys.
*/
parsePoint(rawPoint) {
let m = {};
m["latitude"] = Number(rawPoint[0])
m["longitude"] = Number(rawPoint[1])

return m;
}

/**
* Parse a raw value into its actual value.
* @async
Expand All @@ -293,13 +307,16 @@ class ResultSet {
case ResultSetValueTypes.VALUE_NULL:
scalar = null;
break;

case ResultSetValueTypes.VALUE_STRING:
scalar = String(value);
break;

case ResultSetValueTypes.VALUE_INTEGER:
case ResultSetValueTypes.VALUE_DOUBLE:
scalar = Number(value);
break;

case ResultSetValueTypes.VALUE_BOOLEAN:
if (value === "true") {
scalar = true;
Expand All @@ -309,15 +326,19 @@ class ResultSet {
console.log("Unknown boolean type\n");
}
break;

case ResultSetValueTypes.VALUE_ARRAY:
scalar = this.parseArray(value);
break;

case ResultSetValueTypes.VALUE_NODE:
scalar = await this.parseNode(value);
break;

case ResultSetValueTypes.VALUE_EDGE:
scalar = await this.parseEdge(value);
break;

case ResultSetValueTypes.VALUE_PATH:
scalar = await this.parsePath(value);
break;
Expand All @@ -326,6 +347,10 @@ class ResultSet {
scalar = await this.parseMap(value);
break;

case ResultSetValueTypes.VALUE_POINT:
scalar = this.parsePoint(value);
break;

case ResultSetValueTypes.VALUE_UNKNOWN:
console.log("Unknown scalar type\n");
break;
Expand Down
12 changes: 12 additions & 0 deletions test/redisGraphAPITest.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ describe("RedisGraphAPI Test", () => {
assert.ok(!resultSet.hasNext());
});

it("test point", async () => {
// return point value
let resultSet = await api.query("RETURN point({latitude: 32, longitude: 34})");
assert.equal(resultSet.size(), 1);
assert.ok(resultSet.hasNext());

let record = resultSet.next();
let expected = {latitude: 32, longitude: 34}
assert.deepStrictEqual(expected, record.get(0));
assert.ok(!resultSet.hasNext());
});

it("test multi thread", async () => {
await api.query("CREATE (:person {name:'roi', age:34})");
var promises = [];
Expand Down