Giter Site home page Giter Site logo

neo4j-architect's Introduction

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

neo4j-architect's People

Contributors

flipside avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

neo4j-architect's Issues

Chainable queries

I have a question with chaining two queries and then combining them at the end. I have two separate functions:

var getNodes = new Construct(_matchEmailNodes, _manyNodes);
var getEdges = new Construct(_matchEmailEdges, _manyEdges);

The function want to expose will be getNetwork that will ultimately add these two together. How do I chain these functions so that the output will be these two added?

Some Ideas

Hi Mat, really neat idea.

This is "client-side" what I did with http://github.com/jexp/cypher-rs on the server-side.

I would love if neo4j-architect would be more opinionated for the 80% common use-cases (e.g. CRUD).

  • all(label)
  • create(label, data)
  • update(label, key,value, data)
  • get(label, key, value)
  • deleteAll(label)
  • delete(label, key, value)

And have some convention over configuration defaults for how to handle results.

Automatically:

  • return single column results as a single array
  • return single row, single column result as scalar value
  • return single row, multi column as single JS object
  • convert cypher-rows to javascript objects with the column as keys
  • use a callback for each of those objects to consume, if no callback is passed in, return a promise for an array
  • support query extension, e.g. with order by, or limit, skip for paging

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.