JSPM

neo4j-architect

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q42114F
  • License MIT

Neo4j-Architect constructs functional Neo4j queries

Package Exports

  • neo4j-architect

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (neo4j-architect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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