Neo4j cypher query support
This commit is contained in:
parent
f251ac9a5b
commit
775b6b8b1c
|
@ -45,6 +45,27 @@ Neo4j.prototype.mixClassMethods = function mixClassMethods(class, properties) {
|
|||
}
|
||||
});
|
||||
|
||||
class.setupCypherQuery = function (name, queryStr, rowHandler) {
|
||||
class[name] = function cypherQuery(params, cb) {
|
||||
if (typeof params === 'function') {
|
||||
cb = params;
|
||||
params = [];
|
||||
} else if (params.constructor.name !== 'Array') {
|
||||
params = [params];
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var q = queryStr.replace(/\?/g, function () {
|
||||
return params[i++];
|
||||
});
|
||||
|
||||
neo.client.query(function (err, result) {
|
||||
if (err) return cb(err, []);
|
||||
cb(null, result.map(rowHandler));
|
||||
}, q);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param from - id of object to check relation from
|
||||
* @param to - id of object to check relation to
|
||||
|
@ -228,6 +249,9 @@ Neo4j.prototype.destroy = function destroy(model, id, callback) {
|
|||
|
||||
Neo4j.prototype.all = function all(model, filter, callback) {
|
||||
this.client.queryNodeIndex(model, 'id:*', function (err, nodes) {
|
||||
if (nodes) {
|
||||
nodes = nodes.map(function (s) { return s.data });
|
||||
}
|
||||
callback(err, filter && nodes ? nodes.filter(applyFilter(filter)) : nodes);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue