Skip to content

Commit cf3ba10

Browse files
committed
Initial commit
0 parents  commit cf3ba10

File tree

9 files changed

+432
-0
lines changed

9 files changed

+432
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.settings/
2+
/node_modules/
3+
.project
4+
package-lock.json

.jshintrc

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"esversion": 6,
3+
4+
// --------------------------------------------------------------------
5+
// JSHint Nodeclipse Configuration v0.18
6+
// Strict Edition with some relaxations and switch to Node.js, no `use strict`
7+
// by Ory Band, Michael Haschke, Paul Verest
8+
// https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.ui/templates/common-templates/.jshintrc
9+
// JSHint Documentation is at http://www.jshint.com/docs/options/
10+
// JSHint Integration v0.9.10 comes with JSHInt 2.5.6 , see https://github.com/eclipsesource/jshint-eclipse
11+
// --------------------------------------------------------------------
12+
// from https://gist.github.com/haschek/2595796
13+
//
14+
// This is a options template for [JSHint][1], using [JSHint example][2]
15+
// and [Ory Band's example][3] as basis and setting config values to
16+
// be most strict:
17+
//
18+
// * set all enforcing options to true
19+
// * set all relaxing options to false
20+
// * set all environment options to false, except the node value
21+
// * set all JSLint legacy options to false
22+
//
23+
// [1]: http://www.jshint.com/
24+
// [2]: https://github.com/jshint/node-jshint/blob/master/example/config.json //404
25+
// [3]: https://github.com/oryband/dotfiles/blob/master/jshintrc
26+
// [4]: http://www.jshint.com/options/
27+
//
28+
// @author http://michael.haschke.biz/
29+
// @license http://unlicense.org/
30+
31+
// == Enforcing Options ===============================================
32+
//
33+
// These options tell JSHint to be more strict towards your code. Use
34+
// them if you want to allow only a safe subset of JavaScript, very
35+
// useful when your codebase is shared with a big number of developers
36+
// with different skill levels. Was all true.
37+
38+
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
39+
"curly" : true, // Require {} for every new block or scope.
40+
"eqeqeq" : true, // Require triple equals i.e. `===`.
41+
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
42+
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
43+
"latedef" : true, // Prohibit variable use before definition.
44+
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
45+
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
46+
"noempty" : true, // Prohibit use of empty blocks.
47+
"nonew" : true, // Prohibit use of constructors for side-effects.
48+
"plusplus" : false, // Prohibit use of `++` & `--`. //coding style related only
49+
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
50+
"undef" : true, // Require all non-global variables be declared before they are used.
51+
"strict" : false, // Require `use strict` pragma in every file.
52+
"trailing" : true, // Prohibit trailing whitespaces.
53+
54+
// == Relaxing Options ================================================
55+
//
56+
// These options allow you to suppress certain types of warnings. Use
57+
// them only if you are absolutely positive that you know what you are
58+
// doing. Was all false.
59+
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
60+
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
61+
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
62+
"eqnull" : false, // Tolerate use of `== null`.
63+
//"es5" : true, // Allow EcmaScript 5 syntax. // es5 is default https://github.com/jshint/jshint/issues/1411
64+
"esnext" : false, // Allow ES.next (ECMAScript 6) specific features such as `const` and `let`.
65+
"evil" : false, // Tolerate use of `eval`.
66+
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
67+
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
68+
"globalstrict" : false, // Allow global "use strict" (also enables 'strict').
69+
"iterator" : false, // Allow usage of __iterator__ property.
70+
"lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
71+
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
72+
"laxcomma" : true, // Suppress warnings about comma-first coding style.
73+
"loopfunc" : false, // Allow functions to be defined within loops.
74+
"maxerr" : 100, // This options allows you to set the maximum amount of warnings JSHint will produce before giving up. Default is 50.
75+
"multistr" : false, // Tolerate multi-line strings.
76+
"onecase" : false, // Tolerate switches with just one case.
77+
"proto" : false, // Tolerate __proto__ property. This property is deprecated.
78+
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
79+
"scripturl" : false, // Tolerate script-targeted URLs.
80+
"smarttabs" : false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
81+
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
82+
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
83+
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
84+
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
85+
86+
// == Environments ====================================================
87+
//
88+
// These options pre-define global variables that are exposed by
89+
// popular JavaScript libraries and runtime environments—such as
90+
// browser or node.js. TODO JSHint Documentation has more, but it is not clear since what JSHint version they appeared
91+
"browser" : false, // Standard browser globals e.g. `window`, `document`.
92+
"couch" : false, // Enable globals exposed by CouchDB.
93+
"devel" : false, // Allow development statements e.g. `console.log();`.
94+
"dojo" : false, // Enable globals exposed by Dojo Toolkit.
95+
"jquery" : false, // Enable globals exposed by jQuery JavaScript library.
96+
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
97+
"node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment.
98+
"nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape.
99+
"phantom" : false, //?since version? This option defines globals available when your core is running inside of the PhantomJS runtime environment.
100+
"prototypejs" : false, // Enable globals exposed by Prototype JavaScript framework.
101+
"rhino" : false, // Enable globals available when your code is running inside of the Rhino runtime environment.
102+
"worker" : false, //?since version? This option defines globals available when your code is running inside of a Web Worker.
103+
"wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host.
104+
"yui" : false, //?since version? This option defines globals exposed by the YUI JavaScript framework.
105+
106+
// == JSLint Legacy ===================================================
107+
//
108+
// These options are legacy from JSLint. Aside from bug fixes they will
109+
// not be improved in any way and might be removed at any point.
110+
"nomen" : false, // Prohibit use of initial or trailing underbars in names.
111+
"onevar" : false, // Allow only one `var` statement per function.
112+
"passfail" : false, // Stop on first error.
113+
"white" : false, // Check against strict whitespace and indentation rules.
114+
115+
// == Undocumented Options ============================================
116+
//
117+
// While Michael have found these options in [example1][2] and [example2][3] (already gone 404)
118+
// they are not described in the [JSHint Options documentation][4].
119+
120+
"predef" : [ // Extra globals.
121+
//"exampleVar",
122+
//"anotherCoolGlobal",
123+
//"iLoveDouglas"
124+
"Java", "JavaFX", "$ARG" //no effect
125+
]
126+
//, "indent" : 2 // Specify indentation spacing
127+
}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
# redisgraph.js
4+
5+
6+
7+
## Usage
8+
9+
10+
11+
## Developing
12+
13+
14+
15+
### Tools

examples/RedisGraphExample.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const RedisGraph = require('../src/redisGraph');
2+
3+
4+
let graph = new RedisGraph('social');
5+
6+
graph.query("CREATE (:person{name:'roi',age:32})").then( (res) => {
7+
console.log('@1111')
8+
console.log(res);
9+
});
10+
graph.query("CREATE (:person{name:'amit',age:30})").then( (res) => {
11+
console.log(res);
12+
console.log("AAA " + res.getStatistics().nodesCreated());
13+
});
14+
15+
graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[knows]->(a)").then( (res) => {
16+
console.log('@33333')
17+
console.log(res);
18+
});
19+
//
20+
graph.query("MATCH (a:person)-[knows]->(:person) RETURN a").then( (res) => {
21+
console.log(res);
22+
console.log("AAA " + res.getStatistics().nodesCreated());
23+
});
24+
//
25+
//while(resultSet.hasNext()){
26+
// Record record = resultSet.next();
27+
// System.out.println(record.getString("a.name"));
28+
//}

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "redisgraph.js",
3+
"version": "1.0.0",
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/redisgraphjs.git"
10+
},
11+
"dependencies": {
12+
"redis": "^2.8.0"
13+
},
14+
"devDependencies": {
15+
"mocha": "^5.2.0"
16+
}
17+
}

src/redisGraph.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const redis = require('redis'),
2+
util = require('util'),
3+
ResultSet = require('./resultSet');
4+
5+
/**
6+
* RedisGraph client
7+
*/
8+
module.exports = class RedisGraph {
9+
10+
/**
11+
* Creates a client to a specific graph running on the specific host/post
12+
*
13+
* @param graphId the graph id
14+
* @param host Redis host
15+
* @param port Redis port
16+
*/
17+
constructor(graphId, host, port) {
18+
this._graphId = graphId;
19+
let client = redis.createClient(port, host);
20+
this._sendCommand = util.promisify(client.send_command).bind(client);
21+
}
22+
23+
/**
24+
* Execute a Cypher query
25+
*
26+
* @param query Cypher query
27+
* @return a result set
28+
*/
29+
query(query) {
30+
return this._sendCommand('graph.QUERY',[this._graphId, query])
31+
.then((res) => {
32+
return new ResultSet(res);
33+
});
34+
}
35+
36+
/**
37+
* Deletes the entire graph
38+
*
39+
* @return delete running time statistics
40+
*/
41+
deleteGraph() {
42+
return this._sendCommand('graph.DELETE',[this._graphId, query])
43+
.then((res) => {
44+
return new ResultSet(res);
45+
});
46+
}
47+
48+
};

src/resultSet.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const Statistics = require('./statistics');
2+
3+
/**
4+
* Hold a query result
5+
*/
6+
module.exports = class ResultSet {
7+
8+
9+
constructor(resp) {
10+
11+
this._position = 1;
12+
this._statistics = new Statistics(resp[1]);
13+
this._results = resp[0];
14+
15+
// Empty result set
16+
if(this._results === null || this._results.length === 0) {
17+
this._header = [];
18+
this._totalResults = 0;
19+
} else {
20+
this._header = this._results[0];
21+
22+
// First row is a header row
23+
this._totalResults = this._results.length - 1;
24+
}
25+
}
26+
27+
getHeader(){
28+
return this._header;
29+
}
30+
31+
hasNext() {
32+
return this._position <= this._totalResults;
33+
}
34+
35+
next() {
36+
return this._results[this._position++];
37+
}
38+
39+
getStatistics() {
40+
return this._statistics;
41+
}
42+
};

src/statistics.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
module.exports = class Statistics {
15+
16+
constructor(raw){
17+
this._raw = raw;
18+
}
19+
20+
getStringValue(label) {
21+
return this.getStatistics()[label];
22+
}
23+
24+
/**
25+
* Return the query statistics
26+
*
27+
* @return statistics object
28+
*/
29+
getStatistics(){
30+
if(!this._statistics) {
31+
this._statistics = {};
32+
for(let row of this._raw) {
33+
let touple = row.split(':');
34+
this._statistics[touple[0]] = touple[1].trim();
35+
}
36+
}
37+
return this._statistics;
38+
}
39+
40+
getIntValue(label) {
41+
let value = this.getStringValue(label);
42+
return value ? parseInt(value) : 0;
43+
}
44+
45+
nodesCreated() {
46+
return this.getIntValue(Label.NODES_CREATED);
47+
}
48+
49+
nodesDeleted() {
50+
return this.getIntValue(Label.NODES_DELETED);
51+
}
52+
53+
labelsAdded() {
54+
return this.getIntValue(Label.LABELS_ADDED);
55+
}
56+
57+
relationshipsDeleted() {
58+
return this.getIntValue(Label.RELATIONSHIPS_DELETED);
59+
}
60+
61+
relationshipsCreated() {
62+
return this.getIntValue(Label.RELATIONSHIPS_CREATED);
63+
}
64+
65+
propertiesSet() {
66+
return this.getIntValue(Label.PROPERTIES_SET);
67+
}
68+
}

0 commit comments

Comments
 (0)