Skip to content
This repository was archived by the owner on Aug 27, 2020. It is now read-only.

offlinehacker/bookshelf-transaction-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Bookshelf transaction manager plugin

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •