Skip to content

Commit

Permalink
fix readme.md, example, null value to string. closes #20, closes #18.…
Browse files Browse the repository at this point in the history
… might close #19
  • Loading branch information
DvirDukhan committed Aug 5, 2019
1 parent 1e683d7 commit d7a3e83
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 243 deletions.
44 changes: 22 additions & 22 deletions examples/redisGraphExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ const RedisGraph = require("redisgraph.js").RedisGraph;
let graph = new RedisGraph("social");

graph
.query("CREATE (:person{name:'roi',age:32})")
.then(() => {
return graph.query("CREATE (:person{name:'amit',age:30})");
})
.then(() => {
return graph.query(
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(a)"
);
})
.then(() => {
return graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a");
})
.then(res => {
while (res.hasNext()) {
let record = res.next();
console.log(record.getString("a.name"));
}
console.log(res.getStatistics().queryExecutionTime());
})
.catch(err => {
console.log(err);
});
.query("CREATE (:person{name:'roi',age:32})")
.then(() => {
return graph.query("CREATE (:person{name:'amit',age:30})");
})
.then(() => {
return graph.query(
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)"
);
})
.then(() => {
return graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a");
})
.then(res => {
while (res.hasNext()) {
let record = res.next();
console.log(record.getString("a.name"));
}
console.log(res.getStatistics().queryExecutionTime());
})
.catch(err => {
console.log(err);
});
90 changes: 49 additions & 41 deletions src/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,55 @@
* Hold a query record
*/
class Record {
constructor(header, values) {
this._header = header;
this._values = values;
}

get(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}
return this._values[index];
}

getString(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}

if (this._values[index]) {
return this._values[index].toString();
}

return null;
}

keys() {
return this._header;
}

values() {
return this._values;
}

containsKey(key) {
return this._header.includes(key);
}

size() {
return this._header.length;
}
constructor(header, values) {
this._header = header;
this._values = values;
}

get(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}
return this._values[index];
}

getString(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}

if (this._values[index]) {
return this._values[index].toString();
}

return null;
}

getString(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}
return this._values[index] ? this._values[index].toString() : null;
}

keys() {
return this._header;
}

values() {
return this._values;
}

containsKey(key) {
return this._header.includes(key);
}

size() {
return this._header.length;
}
}

module.exports = Record;
Loading

0 comments on commit d7a3e83

Please sign in to comment.