Skip to content

Commit 90f057c

Browse files
committed
change from require to imports, and make module more easily consumable. Also fix tests which were not passing
1 parent bb55793 commit 90f057c

File tree

12 files changed

+373
-435
lines changed

12 files changed

+373
-435
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015", "stage-3"],
3+
"plugins": []
4+
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.settings/
22
/node_modules/
33
.project
4-
package-lock.json
4+
package-lock.json
5+
yarn.lock

.jshintrc

Lines changed: 0 additions & 127 deletions
This file was deleted.

examples/RedisGraphExample.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
const RedisGraph = require('../src/redisGraph');
1+
const RedisGraph = require("../src/redisGraph");
22

3-
4-
let graph = new RedisGraph('social');
3+
let graph = new RedisGraph("social");
54

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

package.json

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
{
2-
"name": "redisgraph.js",
3-
"version": "1.0.2",
4-
"description": "Connect to RedisGraph 1.0.0 and up from JavaScript",
5-
"author": "RedisLabs",
6-
"license": "BSD 3",
7-
"repository": {
8-
"type": "git",
9-
"url": "git://github.com/redislabs/redisgraph.js.git"
10-
},
11-
"dependencies": {
12-
"redis": "^2.8.0"
13-
},
14-
"devDependencies": {
15-
"mocha": "^5.2.0"
16-
},
17-
"scripts": {
18-
"test": "mocha"
19-
}
2+
"name": "redisgraph.js",
3+
"version": "1.0.2",
4+
"description": "Connect to RedisGraph 1.0.0 and up from JavaScript",
5+
"author": "RedisLabs",
6+
"license": "BSD 3",
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/redislabs/redisgraph.js.git"
10+
},
11+
"dependencies": {
12+
"redis": "^2.8.0"
13+
},
14+
"devDependencies": {
15+
"babel-core": "^6.26.3",
16+
"babel-preset-latest": "^6.24.1",
17+
"babel-preset-stage-3": "^6.24.1",
18+
"mocha": "^5.2.0"
19+
},
20+
"scripts": {
21+
"test": "mocha -R spec --require babel-core/register --exit"
22+
},
23+
"main": "./src/index.js"
2024
}

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Record from "./record";
2+
import RedisGraph from "./redisGraph";
3+
import ResultSet from "./resultSet";
4+
import Statistics from "./statistics";
5+
import Label from "./label";
6+
7+
const redisGraph = {
8+
Record: Record,
9+
RedisGraph: RedisGraph,
10+
ResultSet: ResultSet,
11+
Statistics: Statistics,
12+
Label: Label
13+
};
14+
15+
export default redisGraph;

src/label.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Different Statistics labels
3+
*/
4+
const Label = Object.freeze({
5+
LABELS_ADDED: "Labels added",
6+
NODES_CREATED: "Nodes created",
7+
NODES_DELETED: "Nodes deleted",
8+
RELATIONSHIPS_DELETED: "Relationships deleted",
9+
PROPERTIES_SET: "Properties set",
10+
RELATIONSHIPS_CREATED: "Relationships created",
11+
QUERY_INTERNAL_EXECUTION_TIME: "Query internal execution time"
12+
});
13+
14+
export default Label;

src/record.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
/**
22
* Hold a query record
33
*/
4-
module.exports = class Record {
5-
6-
constructor(header, values){
7-
this._header = header;
8-
this._values = values;
4+
class Record {
5+
constructor(header, values) {
6+
this._header = header;
7+
this._values = values;
8+
}
9+
10+
getString(key) {
11+
let index = key;
12+
if (typeof key === "string") {
13+
index = this._header.indexOf(key);
914
}
10-
11-
getString(key) {
12-
let index = key;
13-
if(typeof key === "string"){
14-
index = this._header.indexOf(key);
15-
}
16-
return this._values[index];
17-
}
15+
return this._values[index];
16+
}
17+
18+
keys() {
19+
return this._header;
20+
}
1821

19-
keys() {
20-
return this._header;
21-
}
22+
values() {
23+
return this._values;
24+
}
2225

23-
values() {
24-
return this._values;
25-
}
26+
containsKey(key) {
27+
return this._header.includes(key);
28+
}
2629

27-
containsKey(key) {
28-
return this._header.includes(key);
29-
}
30+
size() {
31+
return this._header.length;
32+
}
33+
}
3034

31-
size() {
32-
return this._header.length;
33-
}
34-
}
35+
export default Record;

0 commit comments

Comments
 (0)