ORM Transaction

This plugin adds transaction support for ORM.

View the Project on GitHub dresende/node-orm-transaction

ORM Transaction Plugin

This plugin adds a transaction function for ORM.

Dependencies

Of course you need orm to use it. Other than that, no more dependencies.

Install

npm install orm-transaction

DBMS Support

Any driver supported by ORM is supported by this plugin.

Usage

db.transaction(function (err, transaction) {
    // do your stuff
    transaction.commit(function (err) {
        if (!err) {
            console.log("success!");
        }
    });
});

Example

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();
    });
});