Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

bookshelf-cls-transaction

0.1.2 • Public • Published

bookshelf-cls-transaction

A bookshelf plugin that uses continuation-local-storage to store transactions into call stack context. So you don't need to pass transaction into every method, that must be under transaction. This plugin does this automatically.

Examples

Without this plugin:

const user = await bookshelf.transaction(async (trx) => {
  const club = await new Club({ name: 'The Foos' })
    .save(null, { transacting: trx });
  const user = await new User({ name: 'Sam', club_id: club.id })
    .save(null, { transacting: trx });
  return user;
});

With this plugin:

const user = await bookshelf.transaction(async () => {
  const club = await new Club({ name: 'The Foos' }).save();
  const user = await new User({ name: 'Sam', club_id: club.id }).save();
  return user;
});

Installation

Install with npm:

npm i bookshelf-cls-transaction

Add plugin to your bookshelf:

bookshelf.plugin(require('bookshelf-cls-transaction'));

install

npm i bookshelf-cls-transaction

Downloadsweekly downloads

6

version

0.1.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability