Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

A bookshelf plugin that stores transaction in call stack context.

License

Notifications You must be signed in to change notification settings

pyldin601/bookshelf-cls-transaction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A bookshelf plugin that stores transaction in call stack context.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published