Skip to content

Change the Merge use case to leverage proper Neo merging #1

@jclosure

Description

@jclosure

Extend api and simplify by using the cypher MERGE approach. Use this as a guidline:

Entity.merge = function (label, data, callback) {
Object.getOwnPropertyNames(data).forEach(function(key) {
//var val = data[key]);
if (!Entity.prototype.hasOwnProperty(key)) {
Object.defineProperty(Entity.prototype, key, {
get: function () {
return this._node.data[key];
},
set: function (v) {
this._node.data[key] = v;
}
})
}
});

//convert json to cypher literals
var cypherLiterals = JSON.stringify(data).replace(/"([^"]+)":/g,"$1:").replace(/\uFFFF/g,"\"");

var query = [
'MERGE (entity:' + label + ' ' + cypherLiterals + ')',
'RETURN entity',
].join('\n');

db.query(query, {}, function (err, results) {
if (err) return callback(err);
var entity = new Entity(results[0]['entity']);
entity.label = label;
callback(null, entity);
});

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions