seraph_model
v0.1.3
Published
thin model layer for seraph/neo4j
Downloads
3
Readme
seraph_model provides some convenient functions for storing and retrieving typed nodes from a neo4j database. It is intended to work with seraph.
var db = require('seraph')('http://localhost:7474')
var model = require('seraph_model');
var User = model(db, 'user');
User.save({ name: 'Jon', city: 'Bergen' }, function(err, saved) {
if (err) throw err;
User.findAll(function(err, allUsers) {
// allUsers -> [{ name: 'Jon', city: 'Bergen', id: 0 }]
});
User.where({ city: 'Bergen' }, function(err, usersFromBergen) {
// usersFromBergen -> all user objects with city == bergen
});
})
Documentation
__seraph_model(seraphDbObject, modelTypeName)
You can create a new model by calling the function returned by requiring
seraph_model
.
It works by indexing each object under a nodes
index. Each different model is
simply an item in that index, with all of the instances of that model attached
to it.
Saves or updates an object in the database. This is a composition of the
seraph.save
and seraph.index
calls. The object returned is given an ID. See
seraph.save for more
information and an example (they are operationally identical).
Finds all of the objects that were saved with this type.
This is a operationally similar to seraph.find, but is restricted to searching for other objects indexed as this kind of model. See the quick example for an example of this in action.