Skip to content

Commit d7a3e83

Browse files
committed
fix readme.md, example, null value to string. closes #20, closes #18. might close #19
1 parent 1e683d7 commit d7a3e83

File tree

3 files changed

+284
-243
lines changed

3 files changed

+284
-243
lines changed

examples/redisGraphExample.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ const RedisGraph = require("redisgraph.js").RedisGraph;
33
let graph = new RedisGraph("social");
44

55
graph
6-
.query("CREATE (:person{name:'roi',age:32})")
7-
.then(() => {
8-
return graph.query("CREATE (:person{name:'amit',age:30})");
9-
})
10-
.then(() => {
11-
return graph.query(
12-
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(a)"
13-
);
14-
})
15-
.then(() => {
16-
return graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a");
17-
})
18-
.then(res => {
19-
while (res.hasNext()) {
20-
let record = res.next();
21-
console.log(record.getString("a.name"));
22-
}
23-
console.log(res.getStatistics().queryExecutionTime());
24-
})
25-
.catch(err => {
26-
console.log(err);
27-
});
6+
.query("CREATE (:person{name:'roi',age:32})")
7+
.then(() => {
8+
return graph.query("CREATE (:person{name:'amit',age:30})");
9+
})
10+
.then(() => {
11+
return graph.query(
12+
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)"
13+
);
14+
})
15+
.then(() => {
16+
return graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a");
17+
})
18+
.then(res => {
19+
while (res.hasNext()) {
20+
let record = res.next();
21+
console.log(record.getString("a.name"));
22+
}
23+
console.log(res.getStatistics().queryExecutionTime());
24+
})
25+
.catch(err => {
26+
console.log(err);
27+
});

src/record.js

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,55 @@
22
* Hold a query record
33
*/
44
class Record {
5-
constructor(header, values) {
6-
this._header = header;
7-
this._values = values;
8-
}
9-
10-
get(key) {
11-
let index = key;
12-
if (typeof key === "string") {
13-
index = this._header.indexOf(key);
14-
}
15-
return this._values[index];
16-
}
17-
18-
getString(key) {
19-
let index = key;
20-
if (typeof key === "string") {
21-
index = this._header.indexOf(key);
22-
}
23-
24-
if (this._values[index]) {
25-
return this._values[index].toString();
26-
}
27-
28-
return null;
29-
}
30-
31-
keys() {
32-
return this._header;
33-
}
34-
35-
values() {
36-
return this._values;
37-
}
38-
39-
containsKey(key) {
40-
return this._header.includes(key);
41-
}
42-
43-
size() {
44-
return this._header.length;
45-
}
5+
constructor(header, values) {
6+
this._header = header;
7+
this._values = values;
8+
}
9+
10+
get(key) {
11+
let index = key;
12+
if (typeof key === "string") {
13+
index = this._header.indexOf(key);
14+
}
15+
return this._values[index];
16+
}
17+
18+
getString(key) {
19+
let index = key;
20+
if (typeof key === "string") {
21+
index = this._header.indexOf(key);
22+
}
23+
24+
if (this._values[index]) {
25+
return this._values[index].toString();
26+
}
27+
28+
return null;
29+
}
30+
31+
getString(key) {
32+
let index = key;
33+
if (typeof key === "string") {
34+
index = this._header.indexOf(key);
35+
}
36+
return this._values[index] ? this._values[index].toString() : null;
37+
}
38+
39+
keys() {
40+
return this._header;
41+
}
42+
43+
values() {
44+
return this._values;
45+
}
46+
47+
containsKey(key) {
48+
return this._header.includes(key);
49+
}
50+
51+
size() {
52+
return this._header.length;
53+
}
4654
}
4755

4856
module.exports = Record;

0 commit comments

Comments
 (0)