-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from VeliovGroup/dev
v.0.2.1
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters