neo4j-architect

Functional constructor for Neo4j queries and their results.

Showing:

Popularity

Downloads/wk

1

GitHub Stars

6

Maintenance

Last Commit

7yrs ago

Contributors

1

Package

Dependencies

4

Size (min+gzip)

237.3KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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);
      });
    };

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100