Skip to content

Commit 93096f4

Browse files
DvirDukhangkorland
authored andcommitted
comply to 1.99.7 index mutation reply (#31)
* comply to 1.99.7 index mutation reply * added async/await flow. edited readme * formatted with Prettier * added docs * added docs publishing to circleci
1 parent 623b5de commit 93096f4

File tree

14 files changed

+1178
-875
lines changed

14 files changed

+1178
-875
lines changed

.circleci/config.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ jobs:
3535
- run: istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --exit
3636
- run: codecov -t ${CODECOV_TOKEN}
3737

38+
docs:
39+
docker:
40+
- image: circleci/node:10.15
41+
42+
working_directory: ~/repo
43+
44+
steps:
45+
- checkout
46+
- run:
47+
name: Install and configure dependencies
48+
command: |
49+
npm install -g --silent gh-pages@2.0.1
50+
npm install -g --silent jsdoc
51+
git config user.email "ci-build@redisgraph.io"
52+
git config user.name "ci-build"
53+
- add_ssh_keys:
54+
fingerprints:
55+
- "76:ad:7c:fa:32:41:29:d0:cc:f6:63:06:62:b6:54:9c"
56+
- run:
57+
name: Create docs with jsdoc
58+
command: jsdoc ./src -r -d ./docs -R ./README.md
59+
- run:
60+
name: Deploy docs to gh-pages branch
61+
command: gh-pages --dist ./docs --branch master --dest ./docs
62+
3863
workflows:
3964
version: 2
4065
commit:
@@ -50,3 +75,4 @@ workflows:
5075
- master
5176
jobs:
5277
- build
78+
- docs

README.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Installation is done using the
2222
npm install redisgraph.js
2323
```
2424

25+
For installing the latest snapshot use
26+
```bash
27+
npm install github:RedisGraph/redisgraph.js.git
28+
```
29+
30+
2531
## Overview
2632

2733
### Official Releases
@@ -34,39 +40,38 @@ const RedisGraph = require("redisgraph.js").Graph;
3440

3541
let graph = new RedisGraph("social");
3642

37-
graph.query("CREATE (:person{name:'roi',age:32})").then(() => {
38-
graph.query("CREATE (:person{name:'amit',age:30})").then(()=>{
39-
graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)").then(()=>{
40-
graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a.name").then(res=>{
41-
while (res.hasNext()) {
42-
let record = res.next();
43-
console.log(record.get("a.name"));
44-
}
45-
console.log(res.getStatistics().queryExecutionTime());
46-
let param = {'age': 30};
47-
graph.query("MATCH (a {age: $age}) return a.name", param).then(res=>{
48-
while (res.hasNext()) {
49-
let record = res.next();
50-
console.log(record.get("a.name"));
51-
}
52-
graph.query("MATCH p = (a:person)-[:knows]->(:person) RETURN p").then(res=>{
53-
while (res.hasNext()) {
54-
let record = res.next();
55-
// See path.js for more path API.
56-
console.log(record.get("p").nodeCount);
57-
graph.deleteGraph();
58-
process.exit();
59-
}
60-
})
61-
})
62-
})
63-
})
64-
})
65-
})
66-
.catch(err => {
67-
console.log(err);
68-
});
69-
43+
(async () =>{
44+
await graph.query("CREATE (:person{name:'roi',age:32})");
45+
await graph.query("CREATE (:person{name:'amit',age:30})");
46+
await graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)");
47+
48+
// Match query.
49+
let res = await graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a.name");
50+
while (res.hasNext()) {
51+
let record = res.next();
52+
console.log(record.get("a.name"));
53+
}
54+
console.log(res.getStatistics().queryExecutionTime());
55+
56+
// Match with parameters.
57+
let param = {'age': 30};
58+
res = await graph.query("MATCH (a {age: $age}) return a.name", param);
59+
while (res.hasNext()) {
60+
let record = res.next();
61+
console.log(record.get("a.name"));
62+
}
63+
64+
// Named paths matching.
65+
res = await graph.query("MATCH p = (a:person)-[:knows]->(:person) RETURN p");
66+
while (res.hasNext()) {
67+
let record = res.next();
68+
// See path.js for more path API.
69+
console.log(record.get("p").nodeCount);
70+
graph.deleteGraph();
71+
process.exit();
72+
}
73+
74+
})();
7075

7176
```
7277

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "git://github.com/redislabs/redisgraph.js.git"
1010
},
1111
"dependencies": {
12-
"redisgraph.js": "^1.2.0"
12+
"redisgraph.js": "../"
1313
},
1414
"main": "redisGraphExample.js"
1515
}

examples/redisGraphExample.js

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,44 @@ const RedisGraph = require("redisgraph.js").Graph;
22

33
let graph = new RedisGraph("social");
44

5-
graph.query("CREATE (:person{name:'roi',age:32})").then(() => {
6-
graph.query("CREATE (:person{name:'amit',age:30})").then(()=>{
7-
graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)").then(()=>{
8-
graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a.name").then(res=>{
9-
while (res.hasNext()) {
10-
let record = res.next();
11-
console.log(record.get("a.name"));
12-
}
13-
console.log(res.getStatistics().queryExecutionTime());
14-
let param = {'age': 30};
15-
graph.query("MATCH (a {age: $age}) return a.name", param).then(res=>{
16-
while (res.hasNext()) {
17-
let record = res.next();
18-
console.log(record.get("a.name"));
19-
}
20-
graph.query("MATCH p = (a:person)-[:knows]->(:person) RETURN p").then(res=>{
21-
while (res.hasNext()) {
22-
let record = res.next();
23-
// See path.js for more path API.
24-
console.log(record.get("p").nodeCount);
25-
graph.deleteGraph();
26-
process.exit();
27-
}
28-
})
29-
})
30-
})
31-
})
32-
})
33-
})
34-
.catch(err => {
35-
console.log(err);
36-
});
5+
try {
6+
(async () => {
7+
await graph.query("CREATE (:person{name:'roi',age:32})");
8+
await graph.query("CREATE (:person{name:'amit',age:30})");
9+
await graph.query(
10+
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)"
11+
);
12+
13+
// Match query.
14+
let res = await graph.query(
15+
"MATCH (a:person)-[:knows]->(:person) RETURN a.name"
16+
);
17+
while (res.hasNext()) {
18+
let record = res.next();
19+
console.log(record.get("a.name"));
20+
}
21+
console.log(res.getStatistics().queryExecutionTime());
22+
23+
// Match with parameters.
24+
let param = { age: 30 };
25+
res = await graph.query("MATCH (a {age: $age}) return a.name", param);
26+
while (res.hasNext()) {
27+
let record = res.next();
28+
console.log(record.get("a.name"));
29+
}
30+
31+
// Named paths matching.
32+
res = await graph.query(
33+
"MATCH p = (a:person)-[:knows]->(:person) RETURN p"
34+
);
35+
while (res.hasNext()) {
36+
let record = res.next();
37+
// See path.js for more path API.
38+
console.log(record.get("p").nodeCount);
39+
graph.deleteGraph();
40+
process.exit();
41+
}
42+
})();
43+
} catch (err) {
44+
console.log(err);
45+
}

src/edge.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,36 @@
33
* An edge connecting two nodes.
44
*/
55
class Edge {
6-
constructor(srcNode, relation, destNode, properties) {
7-
this.id = undefined; //edge's id - set by RedisGraph
8-
this.relation = relation; //edge's relationship type
9-
this.srcNode = srcNode; //edge's source node
10-
this.destNode = destNode; //edge's destinatio node
11-
this.properties = properties; //edge's list of properties (list of Key:Value)
12-
}
6+
/**
7+
* Builds an Edge object.
8+
* @constructor
9+
* @param {Node} srcNode - Source node of the edge.
10+
* @param {string} relation - Relationship type of the edge.
11+
* @param {Node} destNode - Destination node of the edge.
12+
* @param {Map} properties - Properties map of the edge.
13+
*/
14+
constructor(srcNode, relation, destNode, properties) {
15+
this.id = undefined; //edge's id - set by RedisGraph
16+
this.relation = relation; //edge's relationship type
17+
this.srcNode = srcNode; //edge's source node
18+
this.destNode = destNode; //edge's destination node
19+
this.properties = properties; //edge's list of properties (list of Key:Value)
20+
}
1321

14-
setId(id) {
15-
this.id = id;
16-
}
17-
toString() {
18-
return JSON.stringify(this);
22+
/**
23+
* Sets the edge ID.
24+
* @param {int} id
25+
*/
26+
setId(id) {
27+
this.id = id;
1928
}
29+
30+
/**
31+
* @returns The string representation of the edge.
32+
*/
33+
toString() {
34+
return JSON.stringify(this);
35+
}
2036
}
2137

2238
module.exports = Edge;

0 commit comments

Comments
 (0)