Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ jobs:
- run: istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --exit
- run: codecov -t ${CODECOV_TOKEN}

docs:
docker:
- image: circleci/node:10.15

working_directory: ~/repo

steps:
- checkout
- run:
name: Install and configure dependencies
command: |
npm install -g --silent gh-pages@2.0.1
npm install -g --silent jsdoc
git config user.email "ci-build@redisgraph.io"
git config user.name "ci-build"
- add_ssh_keys:
fingerprints:
- "76:ad:7c:fa:32:41:29:d0:cc:f6:63:06:62:b6:54:9c"
- run:
name: Create docs with jsdoc
command: jsdoc ./src -r -d ./docs -R ./README.md
- run:
name: Deploy docs to gh-pages branch
command: gh-pages --dist ./docs --branch master --dest ./docs

workflows:
version: 2
commit:
Expand All @@ -50,3 +75,4 @@ workflows:
- master
jobs:
- build
- docs
71 changes: 38 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Installation is done using the
npm install redisgraph.js
```

For installing the latest snapshot use
```bash
npm install github:RedisGraph/redisgraph.js.git
```


## Overview

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

let graph = new RedisGraph("social");

graph.query("CREATE (:person{name:'roi',age:32})").then(() => {
graph.query("CREATE (:person{name:'amit',age:30})").then(()=>{
graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)").then(()=>{
graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a.name").then(res=>{
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}
console.log(res.getStatistics().queryExecutionTime());
let param = {'age': 30};
graph.query("MATCH (a {age: $age}) return a.name", param).then(res=>{
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}
graph.query("MATCH p = (a:person)-[:knows]->(:person) RETURN p").then(res=>{
while (res.hasNext()) {
let record = res.next();
// See path.js for more path API.
console.log(record.get("p").nodeCount);
graph.deleteGraph();
process.exit();
}
})
})
})
})
})
})
.catch(err => {
console.log(err);
});

(async () =>{
await graph.query("CREATE (:person{name:'roi',age:32})");
await graph.query("CREATE (:person{name:'amit',age:30})");
await graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)");

// Match query.
let res = await graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a.name");
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}
console.log(res.getStatistics().queryExecutionTime());

// Match with parameters.
let param = {'age': 30};
res = await graph.query("MATCH (a {age: $age}) return a.name", param);
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}

// Named paths matching.
res = await graph.query("MATCH p = (a:person)-[:knows]->(:person) RETURN p");
while (res.hasNext()) {
let record = res.next();
// See path.js for more path API.
console.log(record.get("p").nodeCount);
graph.deleteGraph();
process.exit();
}

})();

```

Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "git://github.com/redislabs/redisgraph.js.git"
},
"dependencies": {
"redisgraph.js": "^1.2.0"
"redisgraph.js": "../"
},
"main": "redisGraphExample.js"
}
73 changes: 41 additions & 32 deletions examples/redisGraphExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,44 @@ const RedisGraph = require("redisgraph.js").Graph;

let graph = new RedisGraph("social");

graph.query("CREATE (:person{name:'roi',age:32})").then(() => {
graph.query("CREATE (:person{name:'amit',age:30})").then(()=>{
graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)").then(()=>{
graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a.name").then(res=>{
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}
console.log(res.getStatistics().queryExecutionTime());
let param = {'age': 30};
graph.query("MATCH (a {age: $age}) return a.name", param).then(res=>{
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}
graph.query("MATCH p = (a:person)-[:knows]->(:person) RETURN p").then(res=>{
while (res.hasNext()) {
let record = res.next();
// See path.js for more path API.
console.log(record.get("p").nodeCount);
graph.deleteGraph();
process.exit();
}
})
})
})
})
})
})
.catch(err => {
console.log(err);
});
try {
(async () => {
await graph.query("CREATE (:person{name:'roi',age:32})");
await graph.query("CREATE (:person{name:'amit',age:30})");
await graph.query(
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)"
);

// Match query.
let res = await graph.query(
"MATCH (a:person)-[:knows]->(:person) RETURN a.name"
);
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}
console.log(res.getStatistics().queryExecutionTime());

// Match with parameters.
let param = { age: 30 };
res = await graph.query("MATCH (a {age: $age}) return a.name", param);
while (res.hasNext()) {
let record = res.next();
console.log(record.get("a.name"));
}

// Named paths matching.
res = await graph.query(
"MATCH p = (a:person)-[:knows]->(:person) RETURN p"
);
while (res.hasNext()) {
let record = res.next();
// See path.js for more path API.
console.log(record.get("p").nodeCount);
graph.deleteGraph();
process.exit();
}
})();
} catch (err) {
console.log(err);
}
40 changes: 28 additions & 12 deletions src/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@
* An edge connecting two nodes.
*/
class Edge {
constructor(srcNode, relation, destNode, properties) {
this.id = undefined; //edge's id - set by RedisGraph
this.relation = relation; //edge's relationship type
this.srcNode = srcNode; //edge's source node
this.destNode = destNode; //edge's destinatio node
this.properties = properties; //edge's list of properties (list of Key:Value)
}
/**
* Builds an Edge object.
* @constructor
* @param {Node} srcNode - Source node of the edge.
* @param {string} relation - Relationship type of the edge.
* @param {Node} destNode - Destination node of the edge.
* @param {Map} properties - Properties map of the edge.
*/
constructor(srcNode, relation, destNode, properties) {
this.id = undefined; //edge's id - set by RedisGraph
this.relation = relation; //edge's relationship type
this.srcNode = srcNode; //edge's source node
this.destNode = destNode; //edge's destination node
this.properties = properties; //edge's list of properties (list of Key:Value)
}

setId(id) {
this.id = id;
}
toString() {
return JSON.stringify(this);
/**
* Sets the edge ID.
* @param {int} id
*/
setId(id) {
this.id = id;
}

/**
* @returns The string representation of the edge.
*/
toString() {
return JSON.stringify(this);
}
}

module.exports = Edge;
Loading