brikteknologier / seraph-model

thin model layer for seraph/neo4j (node.js)
MIT License
111 stars 28 forks source link

Creating multipal models in one request #105

Closed royipr closed 8 years ago

royipr commented 8 years ago

Hi..

Is it possible to create multipal nodes with one request without skipping some of the model features?

for example CREATE (n:USER {someData})-[r:Had]->(p:Computer {data}) I know that this is possible via seraph but if I use db.query it skips some of the model features like model.useTimestamp

jonpacker commented 8 years ago

No, unfortunately there's no official support for this. However, if all you're doing is saving, and you're ok with getting your hands dirty (and a little bit of ugly code), this can work:

var db = require('seraph')();
var model = require('seraph-model');
var user = model(db, 'USER');
user.useTimestamps();

var txn = db.batch();
user.db = txn;
user.save({foo: 'bar'}, function(err, result) { console.log(result) });
user.save({foo2: 'bar2'}, function(err, result) { console.log(result) });
user.db = db;

txn.commit();
// shortly after, the callbacks to the two `save` calls are called.