JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
README.md
package.json

README.md

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(function (err) {
        		if (!err) {
            			console.log("success!");
        		}
    		});
	});
});