Skip to content
 
 

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

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!");
		}
	});
});

Pool 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.create({name: "John"}, t.id, function(err, result) {

		Person.find({ surname: "Doe" }).each(function (person) {
				person.useConnection(t.id).remove(function () {
						t.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(function () {
					t.commit(function (err) {
		        		if (!err) {
		            			console.log("success!");
		        		}
		    		});
				});
		});

	});
});

About

ORM Transaction Plugin

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages