orm-transaction

0.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i orm-transaction

Weekly Downloads

161

Version

0.0.2

License

MIT

Last publish

Collaborators

  • dresende