brikteknologier / seraph

A thin and familiar layer between node and neo4j's REST api.
MIT License
309 stars 59 forks source link

Single statement transactions? #196

Closed gilbert closed 8 years ago

gilbert commented 8 years ago

Hello, I use seraph's .query() method quite often, and it's great. However, I have one query that needs to be a transaction. Would it be possible for you to add a .query_txn() method that does the same thing as .query(), except that it uses the neo4j's transaction endpoint instead?

jonpacker commented 8 years ago

Ok, if I understand you correctly, you only want to do one query in the transaction? Seraph is already using the transaction endpoint to do all queries.

If you want to do multiple queries, unfortunately there's no good support in seraph for that yet. There may be in the future, but I don't have any solid plans for it just yet.

You do, on the other hand, have the option of using the batch API, but it's nowhere near as robust us being able to just throw some cypher queries at the problem. If your queries are not interrelated, you do have the option of doing several queries in a batch (note that batches are atomic, so you can kind of treat them like transactions). For example:

var txn = db.batch();
txn.query("MATCH (user:user) SET user.has_agreed_tos = false");
txn.query("MATCH (tos:terms_of_service) SET tos.markdown = {new_tos}", {new_tos: tos_markdown});
txn.commit(function(err) {
  // done or err
});