Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created September 8, 2012 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiyoh/3671763 to your computer and use it in GitHub Desktop.
Save taiyoh/3671763 to your computer and use it in GitHub Desktop.
var $ = require('jquery-deferred');
function transaction(conn, callback) {
var d = $.Deferred();
d.done(function() {
conn.query('COMMIT');
}).fail(function() {
conn.query('ROLLBACK');
});
conn.query('START TRANSACTION', function() {
callback.apply({
rollback: function() { d.reject.apply(d, arguments); },
commit : function() { d.resolve.apply(d, arguments); }
});
});
return d.promise();
}
exports.transaction = transaction;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment