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'));

Dependents (0)

Package Sidebar

Install

npm i bookshelf-cls-transaction

Weekly Downloads

0

Version

0.1.2

License

MIT

Last publish

Collaborators

  • pldin601