0.2.4 • Published 9 years ago

bookshelf-transaction-manager v0.2.4

Weekly downloads
28
License
MIT
Repository
github
Last release
9 years ago

Bookshelf transaction manager

This plugin works with Bookshelf.js, available here http://bookshelfjs.org. It provides transaction manager, which makes managment of database transactions simpler. Transaction manager injects transactions into every bookshelf object or collection, in transaction scope, so that you don't have to pass transaction around.

Installation

npm install bookshelf-transaction-manager

Then in your bookshelf configuration:

var bookshelf = require('bookshelf')(knex);
bookshelf.plugin('registry')
bookshelf.plugin(require('bookshelf-transaction-manager');

Usage

Insted of passing transaction around

bookshelf.transaction(function(trx) {
    trx.model('Model').forge().fetch({transacting: trx}).then(function(model) {
        model.load(['relation'], {transacting: trx}).then(function(model) {
            model.set('key', 'value');
            return model.save({transacting: trx});
        })
    })
})

Just use transaction manager

bookshelf.withTransaction(function(trx) {
    trx.model('Model').forge().fetch().then(function(model) {
        model.load(['relation']).then(function(model) {
            model.set('key', 'value');
            model.save();
        })
    })
})

Other bookshelf functions on models and collections also have transaction passed. You can still override transaction.

License

MIT

Author

offlinehacker

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago