orm-transaction

ORM Transactions

npm install orm-transaction
5 downloads in the last day
30 downloads in the last week
104 downloads in the last month

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