Skip to content

Commit 1287f21

Browse files
authored
Merge pull request #22 from RedisGraph/array_support
added array support
2 parents 1e683d7 + 717fc45 commit 1287f21

File tree

2 files changed

+300
-199
lines changed

2 files changed

+300
-199
lines changed

src/resultSet.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ const ResultSetColumnTypes = {
1010
COLUMN_RELATION: 3
1111
}
1212

13-
const ResultSetScalarTypes = {
14-
PROPERTY_UNKNOWN: 0,
15-
PROPERTY_NULL: 1,
16-
PROPERTY_STRING: 2,
17-
PROPERTY_INTEGER: 3,
18-
PROPERTY_BOOLEAN: 4,
19-
PROPERTY_DOUBLE: 5
13+
const ResultSetValueTypes = {
14+
VALUE_UNKNOWN: 0,
15+
VALUE_NULL: 1,
16+
VALUE_STRING: 2,
17+
VALUE_INTEGER: 3,
18+
VALUE_BOOLEAN: 4,
19+
VALUE_DOUBLE: 5,
20+
VALUE_ARRAY: 6,
21+
VALUE_EDGE: 7,
22+
VALUE_NODE: 8
2023
}
2124

2225
/**
@@ -90,7 +93,7 @@ class ResultSet {
9093
let cellType = this._header[j][0];
9194
switch (cellType) {
9295
case ResultSetColumnTypes.COLUMN_SCALAR:
93-
record[j] = this.parseScalar(cell);
96+
record[j] = await this.parseScalar(cell);
9497
break;
9598
case ResultSetColumnTypes.COLUMN_NODE:
9699
record[j] = await this.parseNode(cell);
@@ -116,14 +119,14 @@ class ResultSet {
116119
let prop_name = this._graph.getProperty(propIndex);
117120
// will try to get the right property for at most 10 times
118121
var tries = 0;
119-
while (prop_name == undefined && tries <10) {
122+
while (prop_name == undefined && tries < 10) {
120123
prop_name = await this._graph.fetchAndGetProperty(propIndex);
121124
tries++;
122125
}
123126
if (prop_name == undefined) {
124127
console.warn("unable to retrive property name value for propety index " + propIndex);
125128
}
126-
let prop_value = this.parseScalar(prop.slice(1, prop.length));
129+
let prop_value = await this.parseScalar(prop.slice(1, prop.length));
127130
properties[prop_name] = prop_value;
128131
}
129132
return properties;
@@ -177,23 +180,30 @@ class ResultSet {
177180
return edge;
178181
}
179182

180-
parseScalar(cell) {
183+
async parseArray(rawArray) {
184+
for (var i = 0; i < rawArray.length; i++) {
185+
rawArray[i] = await this.parseScalar(rawArray[i]);
186+
}
187+
return rawArray;
188+
}
189+
190+
async parseScalar(cell) {
181191
let scalar_type = cell[0];
182192
let value = cell[1];
183193
let scalar = undefined;
184194

185195
switch (scalar_type) {
186-
case ResultSetScalarTypes.PROPERTY_NULL:
196+
case ResultSetValueTypes.VALUE_NULL:
187197
scalar = null;
188198
break;
189-
case ResultSetScalarTypes.PROPERTY_STRING:
199+
case ResultSetValueTypes.VALUE_STRING:
190200
scalar = String(value);
191201
break;
192-
case ResultSetScalarTypes.PROPERTY_INTEGER:
193-
case ResultSetScalarTypes.PROPERTY_DOUBLE:
202+
case ResultSetValueTypes.VALUE_INTEGER:
203+
case ResultSetValueTypes.VALUE_DOUBLE:
194204
scalar = Number(value);
195205
break;
196-
case ResultSetScalarTypes.PROPERTY_BOOLEAN:
206+
case ResultSetValueTypes.VALUE_BOOLEAN:
197207
if (value === "true") {
198208
scalar = true;
199209
} else if (value === "false") {
@@ -202,7 +212,16 @@ class ResultSet {
202212
console.log("Unknown boolean type\n");
203213
}
204214
break;
205-
case ResultSetScalarTypes.PROPERTY_UNKNOWN:
215+
case ResultSetValueTypes.VALUE_ARRAY:
216+
scalar = this.parseArray(value);
217+
break;
218+
case ResultSetValueTypes.VALUE_NODE:
219+
scalar = await this.parseNode(value);
220+
break;
221+
case ResultSetValueTypes.VALUE_EDGE:
222+
scalar = await this.parseEdge(value);
223+
break;
224+
case ResultSetValueTypes.VALUE_UNKNOWN:
206225
console.log("Unknown scalar type\n");
207226
break;
208227
}

0 commit comments

Comments
 (0)