Skip to content

Commit

Permalink
Merge pull request #1 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
v.0.2.1
  • Loading branch information
dr-dimitru committed Dec 5, 2014
2 parents 782d7d6 + e8cd7e1 commit bc780c4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
67 changes: 65 additions & 2 deletions ostrio:neo4jdriver.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,73 @@
/*
*
* @function
* @name Neo4j
* @description Get GraphDatabase from node-neo4j npm package
*
*/
this.Neo4j = (function() {
/*
*
* @function
* @name Neo4j
* @param url {string} - url to Neo4j database
* @description Get GraphDatabase from node-neo4j npm package
*
*/
function Neo4j(url) {
this.url = url != null ? url : process.env['NEO4J_URL'] || process.env['GRAPHENEDB_URL'] || 'http://localhost:7474';
this.N4j = Meteor.npmRequire('neo4j');
return new this.N4j.GraphDatabase(this.url);
_n4j = this.N4j;

var GraphDatabase = new _n4j.GraphDatabase(this.url);
GraphDatabase.callbacks = []

/*
*
* @function
* @namespace N4j.GraphDatabase
* @name query
* @param query {String} - The Cypher query. NOTE: Can't be multi-line.
* @param opts {Object} - A map of parameters for the Cypher query.
* @param callback {function} - Callback function
* @description Replace standard GraphDatabase.query method
* Add functionality of callbacks which runs on every query execution
*
*/
GraphDatabase.query = function(query, opts, callback){

return new _n4j.GraphDatabase(this.url).query(query, opts, function(err, results){

_.forEach(GraphDatabase.callbacks, function(cb){
if(cb){
cb(query, opts);
}
});

if(callback){
callback(err, results);
}
});
}

/*
*
* @function
* @namespace N4j.GraphDatabase
* @name listen
* param callback {function} - Callback function with:
* @param query {String} - The Cypher query. NOTE: Can't be multi-line.
* @param opts {Object} - A map of parameters for the Cypher query.
* @description Add callback function
*
*/
GraphDatabase.listen = function(callback){

GraphDatabase.callbacks.push(callback);
}

return GraphDatabase;
}

return Neo4j;

})();
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'ostrio:neo4jdriver',
summary: 'Meteor.js node-neo4j wrapper to be used with meteor applications (a.k.a. neo4j Connector)',
version: '0.1.13',
version: '0.2.1',
git: 'https://github.com/VeliovGroup/ostrio-neo4jdriver.git'
});

Expand Down
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ N4JDB.query 'Match (o:User {_id:"' + Meteor.userId() + '"}) ' +
#handle error here
```

```coffeescript
###
Register catch all callback
Note - you may register as meny callbacks as you need
@param query {string} - Cypher query
@param opts {object} - A map of parameters for the Cypher query
###
N4JDB = new Neo4j()
N4JDB.listen (query, opts) ->
console.log query, opts

```

**For more info see: [node-neo4j](https://github.com/thingdom/node-neo4j)**
Code licensed under Apache v. 2.0: [node-neo4j License](https://github.com/thingdom/node-neo4j/blob/master/LICENSE)

Expand Down

0 comments on commit bc780c4

Please sign in to comment.