bookshelf-transaction-manager

0.2.4 • Public • Published

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

Package Sidebar

Install

npm i bookshelf-transaction-manager

Weekly Downloads

1

Version

0.2.4

License

MIT

Last publish

Collaborators

  • golobitch
  • tomaztodorovski
  • lukaermencgh
  • enejm-gatehub
  • matejromih
  • x-gh
  • rokbacnar
  • matevz-gh
  • _ana_