Skip to content

Index #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 3, 2019
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.settings/
/node_modules/
.project
package-lock.json
package-lock.json
yarn.lock
/examples/node_modules
127 changes: 0 additions & 127 deletions .jshintrc

This file was deleted.

26 changes: 0 additions & 26 deletions examples/RedisGraphExample.js

This file was deleted.

15 changes: 15 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "redisgraph-example",
"version": "1.0.0",
"description": "Example using redisgraph.js",
"author": "RedisLabs",
"license": "BSD 3",
"repository": {
"type": "git",
"url": "git://github.com/redislabs/redisgraph.js.git"
},
"dependencies": {
"redisgraph.js": "^1.1.0"
},
"main": "redisGraphExample.js"
}
27 changes: 27 additions & 0 deletions examples/redisGraphExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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);
});
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Record = require("./src/record"),
RedisGraph = require("./src/redisGraph"),
ResultSet = require("./src/resultSet"),
Statistics = require("./src/statistics"),
Label = require("./label");

module.exports = {
Record: Record,
RedisGraph: RedisGraph,
ResultSet: ResultSet,
Statistics: Statistics,
Label: Label
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redisgraph.js",
"version": "1.0.4",
"version": "1.1.0",
"description": "Connect to RedisGraph 1.0.0 and up from JavaScript",
"author": "RedisLabs",
"license": "BSD 3",
Expand All @@ -16,5 +16,6 @@
},
"scripts": {
"test": "mocha --exit"
}
},
"main": "index.js"
}
14 changes: 14 additions & 0 deletions src/label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Different Statistics labels
*/
var Label = Object.freeze({
LABELS_ADDED: "Labels added",
NODES_CREATED: "Nodes created",
NODES_DELETED: "Nodes deleted",
RELATIONSHIPS_DELETED: "Relationships deleted",
PROPERTIES_SET: "Properties set",
RELATIONSHIPS_CREATED: "Relationships created",
QUERY_INTERNAL_EXECUTION_TIME: "Query internal execution time"
});

module.exports = Label;
21 changes: 11 additions & 10 deletions src/record.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/**
* Hold a query record
*/
module.exports = class Record {

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

class Record {
constructor(header, values) {
this._header = header;
this._values = values;
}

getString(key) {
let index = key;
if(typeof key === "string"){
if (typeof key === "string") {
index = this._header.indexOf(key);
}
return this._values[index];
Expand All @@ -30,5 +29,7 @@ module.exports = class Record {

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

module.exports = Record;
59 changes: 31 additions & 28 deletions src/redisGraph.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
const redis = require('redis'),
util = require('util'),
ResultSet = require('./resultSet');
const redis = require("redis"),
util = require("util"),
ResultSet = require("./resultSet");

/**
* RedisGraph client
*/
module.exports = class RedisGraph {

class RedisGraph {
/**
* Creates a client to a specific graph running on the specific host/post
* See: node_redis for more options on createClient
* See: node_redis for more options on createClient
*
* @param graphId the graph id
* @param host Redis host or node_redis client
* @param port Redis port
* @param options node_redis options
*/
constructor(graphId, host, port, options) {
this._graphId = graphId;
let client = (host instanceof redis.RedisClient) ? host : redis.createClient.apply(redis, [].slice.call(arguments,1));
this._graphId = graphId;
let client =
host instanceof redis.RedisClient
? host
: redis.createClient.apply(redis, [].slice.call(arguments, 1));
this._sendCommand = util.promisify(client.send_command).bind(client);
}

/**
* Execute a Cypher query
*
*
* @param query Cypher query
* @return a result set
* @return a result set
*/
query(query) {
return this._sendCommand('graph.QUERY',[this._graphId, query])
.then((res) => {
return new ResultSet(res);
});
query(query) {
return this._sendCommand("graph.QUERY", [this._graphId, query]).then(
res => {
return new ResultSet(res);
}
);
}

/**
* Deletes the entire graph
*
* @return delete running time statistics
*/
deleteGraph() {
return this._sendCommand('graph.DELETE',[this._graphId])
.then((res) => {

/**
* Deletes the entire graph
*
* @return delete running time statistics
*/
deleteGraph() {
return this._sendCommand("graph.DELETE", [this._graphId]).then(res => {
return new ResultSet(res);
});
}

};
}
}

module.exports = RedisGraph;
Loading