2.1.0 • Published 9 years ago

codex-orm v2.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
9 years ago

Codex ORM

Build Status devDependency Status Coverage Status npm version Slack Status

Build a graph and query it.

Powered by Neo4j 3, Bolt, and cypher-stream.

Install

npm install --save codex-orm

Example Usage

Creating a Tree with Access Control

'use strict';
var codex = require('codex-orm');
var R     = require('ramda');

var saveTo = R.curry((target, x) =>
  x.save(target)
);

var adopt = R.curry((parent, child) =>
  parent.addChild(child)
);

var create = R.curry((type, properties) =>
  new codex.Graph.Node(type, properties)
);

var tx = new codex.db.Transaction();

var childCount = 5;
var save = R.map(saveTo(tx));
var make = R.compose(save, create);

var parent = make('Parent', {});

var children = R.times(i =>
  make('Child', { name: `Child ${i}`, i }),
  childCount
);

children.map(adopt(parent)).map(save);

children.map(child => R.times(
  i => make('Grand Child', { name: `Grand Child ${i}`, i })
    .map(adopt(child))
    .map(save),
  childCount
));


var bob = new codex.Graph.User({ name: 'Bob' }).save(tx);
var sue = new codex.Graph.User({ name: 'Sue' }).save(tx);

tx.concat(bob.grantAccessTo(parent));
tx.concat(sue.grantAccessTo(children[3]));

tx.concat(parent.findRelated('Child', { accessor: sue })); // Finds the 1 Child node which Sue has access to

tx.concat(parent.findRelated('Child', { accessor: bob })); // Finds all 5 Child nodes.

tx.commit();

The resulting graph

The resulting graph.

Check the tests for more examples.