This plugin adds transaction support for ORM.
This plugin adds a transaction function for ORM.
Of course you need orm
to use it. Other than that, no more dependencies.
npm install orm-transaction
Any driver supported by ORM is supported by this plugin.
db.transaction(function (err, transaction) {
// do your stuff
transaction.commit(function (err) {
if (!err) {
console.log("success!");
}
});
});
var orm = require("orm");
var transaction = require("orm-transaction");
orm.connect("mysql://username:password@host/database", function (err, db) {
if (err) throw err;
db.use(transaction);
var Person = db.define("person", {
name : String,
surname : String,
age : Number
});
db.transaction(function (err, t) {
Person.find({ surname: "Doe" }).each(function (person) {
person.remove();
});
t.commit();
});
});