node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

Transaction support

Open gramakri opened this issue 10 years ago • 8 comments

Transactions can be performed either using

  • db.exec("BEGIN TRANSACTION; ... ; COMMIT") - When creating multi-statement strings, I cannot find a way to escape the values using sqlite3. It would be nice to either export an escape() function for arguments or allow an argument array/binding just like run/all/get.
  • Using db.serialize(function() { /* issue one or more db.run() commands */ }); I cannot see where to issue ROLLBACK or COMMIT if one of the queries in the transaction fail.
db.serialize(function () {
  db.run('begin transcation');
  db.run('some_command1', function (err) { });
  db.run('some_command2', function (err) { });
  // now need to issue rollback or commit based on success/failure of above 2 commands
});

Note that we cannot call rollback/commit in the callbacks of db.run() because they aren't part of the serialize.

Am I missing something obvious?

gramakri avatar Jun 05 '14 04:06 gramakri