Wrapper for node-neo4j by The Thingdom to be used with Meteor apps
Install to meteor
meteor add ostrio:neo4jdriver
Usage
npm install neo4j
In your code:
Create file in ./server/lib/Neo4jDriver.js
1this.N4JDB = new Neo4j(); //From this point N4JDB variable available everywhere in your project
Next, just use it.
Examples:
1var node = N4JDB.createNode({hello: 'world'}); // instantaneous, but... 2node.save(function (err, node) { // ...this is what actually persists. 3 if (err) { 4 console.error('Error saving new node to database:', err); 5 } else { 6 console.log('Node saved to database with id:', node.id); 7 } 8});
1/* 2 * Create user node with _id 3 */ 4Accounts.onCreateUser(function(options, user) { 5 6 N4JDB.query('CREATE (:User {_id:"' + user._id + '"})', null, function(err, res){ 7 if(error){ 8 //handle error here 9 } 10 }); 11});
1### 2This example in coffee 3Here we create some group and set our user as it's owner 4Next, we add relation :owns from owner to newly created group in one query 5### 6groupId = GroupsCollection.insert title: 'Some Group Title', (error) -> 7 error if error 8 #handle error here 9 10N4JDB.query 'Match (o:User {_id:"' + Meteor.userId() + '"}) ' + 11 'CREATE (g:Group {_id:"' + groupId + '", owner: "' + Meteor.userId() + '", active: true}) ' + 12 'CREATE (o) -[:owns]-> (g)', null, (error, res) -> 13 error if error 14 #handle error here
1### 2Register catch all callback 3Note - you may register as meny callbacks as you need 4@param query {string} - Cypher query 5@param opts {object} - A map of parameters for the Cypher query 6### 7N4JDB = new Neo4j() 8N4JDB.listen (query, opts) -> 9 console.log query, opts 10
For more info see: node-neo4j Code licensed under Apache v. 2.0: node-neo4j License
Testing & Dev usage
Local usage
- Download (or clone) to local dir
- Stop meteor if running
- Run
mrt link-package [*full path to folder with package*]
in a project dir - Then run
meteor add ostrio:neo4jdriver
- Run
meteor
in a project dir - From now any changes in ostrio:neo4jdriver package folder will cause rebuilding of project app