Skip to content

Commit d2c9195

Browse files
author
DvirDukhan
committed
added array support
1 parent 1e683d7 commit d2c9195

File tree

2 files changed

+328
-192
lines changed

2 files changed

+328
-192
lines changed

src/resultSet.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const ResultSetColumnTypes = {
1010
COLUMN_RELATION: 3
1111
}
1212

13+
/* deprecated */
1314
const ResultSetScalarTypes = {
1415
PROPERTY_UNKNOWN: 0,
1516
PROPERTY_NULL: 1,
@@ -19,6 +20,18 @@ const ResultSetScalarTypes = {
1920
PROPERTY_DOUBLE: 5
2021
}
2122

23+
const ResultSetValueTypes = {
24+
VALUE_UNKNOWN: 0,
25+
VALUE_NULL: 1,
26+
VALUE_STRING: 2,
27+
VALUE_INTEGER: 3,
28+
VALUE_BOOLEAN: 4,
29+
VALUE_DOUBLE: 5,
30+
VALUE_ARRAY: 6,
31+
VALUE_EDGE: 7,
32+
VALUE_NODE: 8
33+
}
34+
2235
/**
2336
* Hold a query result
2437
*/
@@ -90,7 +103,7 @@ class ResultSet {
90103
let cellType = this._header[j][0];
91104
switch (cellType) {
92105
case ResultSetColumnTypes.COLUMN_SCALAR:
93-
record[j] = this.parseScalar(cell);
106+
record[j] = await this.parseScalar(cell);
94107
break;
95108
case ResultSetColumnTypes.COLUMN_NODE:
96109
record[j] = await this.parseNode(cell);
@@ -116,14 +129,14 @@ class ResultSet {
116129
let prop_name = this._graph.getProperty(propIndex);
117130
// will try to get the right property for at most 10 times
118131
var tries = 0;
119-
while (prop_name == undefined && tries <10) {
132+
while (prop_name == undefined && tries < 10) {
120133
prop_name = await this._graph.fetchAndGetProperty(propIndex);
121134
tries++;
122135
}
123136
if (prop_name == undefined) {
124137
console.warn("unable to retrive property name value for propety index " + propIndex);
125138
}
126-
let prop_value = this.parseScalar(prop.slice(1, prop.length));
139+
let prop_value = await this.parseScalar(prop.slice(1, prop.length));
127140
properties[prop_name] = prop_value;
128141
}
129142
return properties;
@@ -177,23 +190,31 @@ class ResultSet {
177190
return edge;
178191
}
179192

180-
parseScalar(cell) {
193+
async parseArray(rawArray) {
194+
let res = [];
195+
for (var i = 0; i < rawArray.length; i++) {
196+
res.push(await this.parseScalar(rawArray[i]));
197+
}
198+
return res;
199+
}
200+
201+
async parseScalar(cell) {
181202
let scalar_type = cell[0];
182203
let value = cell[1];
183204
let scalar = undefined;
184205

185206
switch (scalar_type) {
186-
case ResultSetScalarTypes.PROPERTY_NULL:
207+
case ResultSetValueTypes.VALUE_NULL:
187208
scalar = null;
188209
break;
189-
case ResultSetScalarTypes.PROPERTY_STRING:
210+
case ResultSetValueTypes.VALUE_STRING:
190211
scalar = String(value);
191212
break;
192-
case ResultSetScalarTypes.PROPERTY_INTEGER:
193-
case ResultSetScalarTypes.PROPERTY_DOUBLE:
213+
case ResultSetValueTypes.VALUE_INTEGER:
214+
case ResultSetValueTypes.VALUE_DOUBLE:
194215
scalar = Number(value);
195216
break;
196-
case ResultSetScalarTypes.PROPERTY_BOOLEAN:
217+
case ResultSetValueTypes.VALUE_BOOLEAN:
197218
if (value === "true") {
198219
scalar = true;
199220
} else if (value === "false") {
@@ -202,7 +223,16 @@ class ResultSet {
202223
console.log("Unknown boolean type\n");
203224
}
204225
break;
205-
case ResultSetScalarTypes.PROPERTY_UNKNOWN:
226+
case ResultSetValueTypes.VALUE_ARRAY:
227+
scalar = this.parseArray(value);
228+
break;
229+
case ResultSetValueTypes.VALUE_NODE:
230+
scalar = await this.parseNode(value);
231+
break;
232+
case ResultSetValueTypes.VALUE_EDGE:
233+
scalar = await this.parseEdge(value);
234+
break;
235+
case ResultSetValueTypes.VALUE_UNKNOWN:
206236
console.log("Unknown scalar type\n");
207237
break;
208238
}

0 commit comments

Comments
 (0)