node package manager

neo4j-architect

neo4j-architect

Functional constructor for Neo4j queries and their results.

Basically, this makes it easy to combine and chain neo4j queries together.

It will also return an array of all the cypher queries, params and results if you pass in {neo4j: true} or {queries: true}. Queries for use with Neo4j-Swagger.

Check out users.js for an implementation.

In use at Neo4j-Swagger.

Big plans, more to come! Pull-requests welcome!

Setup

 
    // .env file 
    NEO4J_URL=YOUR_NEO4J_URL
 
    // set the neo4j URL, only needs to be done once 
    var Architect = require('neo4j-architect');
    Architect.init(url);  // defaults: (url || process.env.NEO4J_URL || 'http://localhost:7474') 

Model

    // user.js 
 
    var Architect = require('neo4j-architect');
    Architect.init();
    var Construct = Architect.Construct;
 
    // construct the cypher query and params 
    var _getSingleUserQuery = function (params, callback) {
      var cypher_params = {
        id: params.id
      };
 
      var query = [
        'MATCH (user:User)',
        'WHERE user.id = {id}'
        'RETURN user'
      ].join('\n');
 
      callback(null, query, cypher_params);
    }
 
    // extract the data from the cypher results 
    var _singleUserResult = function (results, callback) {
      if (results.length) {
        callback(null, results[0].user._node.data);
      } else {
        callback(null, null);
      }
    }
 
    var getUser = new Construct().query(_getSingleUserQuery).then(_singleUserResult);
    var createUser = new Construct(_createUserQuery, _singleUserResult);
    var createUsers = new Construct().then(_createManySetupParams).map(createUser)
 
    module.exports = {
      getUser: getUser.fn(),
      createUser: createUser.fn(),
      createUsers: createUsers.fn()
    };

Route

    var Users = require('./user.js');
 
    // set options to {neo4j: true} or {queries: true} to return all queries/results 
    exports.getUser = function (id, options, callback) {
      Users.getUser({id: id}, options, function (err, results, queries) {
        callback(err, results, queries);
      });
    };

Links

License

MIT