Skip to content

Commit e467447

Browse files
authored
Merge pull request #8 from RedisGraph/index
Index
2 parents 9885cb9 + bcfaf04 commit e467447

13 files changed

+258
-325
lines changed

.gitignore

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

.jshintrc

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

examples/RedisGraphExample.js

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

examples/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "redisgraph-example",
3+
"version": "1.0.0",
4+
"description": "Example using redisgraph.js",
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+
"redisgraph.js": "^1.1.0"
13+
},
14+
"main": "redisGraphExample.js"
15+
}

examples/redisGraphExample.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const RedisGraph = require("redisgraph.js").RedisGraph;
2+
3+
let graph = new RedisGraph("social");
4+
5+
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+
});

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const Record = require("./src/record"),
2+
RedisGraph = require("./src/redisGraph"),
3+
ResultSet = require("./src/resultSet"),
4+
Statistics = require("./src/statistics"),
5+
Label = require("./label");
6+
7+
module.exports = {
8+
Record: Record,
9+
RedisGraph: RedisGraph,
10+
ResultSet: ResultSet,
11+
Statistics: Statistics,
12+
Label: Label
13+
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redisgraph.js",
3-
"version": "1.0.4",
3+
"version": "1.1.0",
44
"description": "Connect to RedisGraph 1.0.0 and up from JavaScript",
55
"author": "RedisLabs",
66
"license": "BSD 3",
@@ -16,5 +16,6 @@
1616
},
1717
"scripts": {
1818
"test": "mocha --exit"
19-
}
19+
},
20+
"main": "index.js"
2021
}

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+
var 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+
module.exports = Label;

src/record.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
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;
9-
}
10-
4+
class Record {
5+
constructor(header, values) {
6+
this._header = header;
7+
this._values = values;
8+
}
9+
1110
getString(key) {
1211
let index = key;
13-
if(typeof key === "string"){
12+
if (typeof key === "string") {
1413
index = this._header.indexOf(key);
1514
}
1615
return this._values[index];
@@ -30,5 +29,7 @@ module.exports = class Record {
3029

3130
size() {
3231
return this._header.length;
33-
}
34-
}
32+
}
33+
}
34+
35+
module.exports = Record;

src/redisGraph.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
1-
const redis = require('redis'),
2-
util = require('util'),
3-
ResultSet = require('./resultSet');
1+
const redis = require("redis"),
2+
util = require("util"),
3+
ResultSet = require("./resultSet");
44

55
/**
66
* RedisGraph client
77
*/
8-
module.exports = class RedisGraph {
9-
8+
class RedisGraph {
109
/**
1110
* Creates a client to a specific graph running on the specific host/post
12-
* See: node_redis for more options on createClient
11+
* See: node_redis for more options on createClient
1312
*
1413
* @param graphId the graph id
1514
* @param host Redis host or node_redis client
1615
* @param port Redis port
1716
* @param options node_redis options
1817
*/
1918
constructor(graphId, host, port, options) {
20-
this._graphId = graphId;
21-
let client = (host instanceof redis.RedisClient) ? host : redis.createClient.apply(redis, [].slice.call(arguments,1));
19+
this._graphId = graphId;
20+
let client =
21+
host instanceof redis.RedisClient
22+
? host
23+
: redis.createClient.apply(redis, [].slice.call(arguments, 1));
2224
this._sendCommand = util.promisify(client.send_command).bind(client);
2325
}
24-
26+
2527
/**
2628
* Execute a Cypher query
27-
*
29+
*
2830
* @param query Cypher query
29-
* @return a result set
31+
* @return a result set
3032
*/
31-
query(query) {
32-
return this._sendCommand('graph.QUERY',[this._graphId, query])
33-
.then((res) => {
34-
return new ResultSet(res);
35-
});
33+
query(query) {
34+
return this._sendCommand("graph.QUERY", [this._graphId, query]).then(
35+
res => {
36+
return new ResultSet(res);
37+
}
38+
);
3639
}
37-
38-
/**
39-
* Deletes the entire graph
40-
*
41-
* @return delete running time statistics
42-
*/
43-
deleteGraph() {
44-
return this._sendCommand('graph.DELETE',[this._graphId])
45-
.then((res) => {
40+
41+
/**
42+
* Deletes the entire graph
43+
*
44+
* @return delete running time statistics
45+
*/
46+
deleteGraph() {
47+
return this._sendCommand("graph.DELETE", [this._graphId]).then(res => {
4648
return new ResultSet(res);
4749
});
48-
}
49-
50-
};
50+
}
51+
}
52+
53+
module.exports = RedisGraph;

0 commit comments

Comments
 (0)