Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

documented commit/rollback feature

  • Loading branch information...
commit 96f2a57c82acd2d4cf6321413bfb2992ac1a0991 1 parent 1d371da
Bruno Jouhier authored
Showing with 34 additions and 0 deletions.
  1. +34 −0 README.md
34 README.md
View
@@ -504,6 +504,40 @@ transaction open per session and transactions cannot be nested.
...
});
+Commit and Rollback
+-------------------
+
+`persistence.js` works in autocommit mode by default.
+
+You can override this behavior and enable explicit commit and rollback
+by passing true as first argument to `persistence.transaction`.
+You can then use the following two methods to control the transaction:
+
+* `transaction.commit(session, callback)` commits the changes.
+* `transaction.rollback(session, callback)` rollbacks the changes.
+
+Typical code will look like:
+
+ session.transaction(true, function(tx) {
+ // create/update/delete objects
+ modifyThings(session, tx, function(err, result) {
+ if (err) {
+ // something went wrong
+ tx.rollback(session, function() {
+ console.log('changes have been rolled back: ' + ex.message);
+ });
+ }
+ else {
+ // success
+ tx.commit(session, function() {
+ console.log('changes have been committed: ' result);
+ });
+ });
+ });
+
+Explicit commit and rollback is only supported on MySQL (server side)
+for now.
+
Defining your data model
------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.