项目作者: pldin601

项目描述 :
A bookshelf plugin that stores transaction in call stack context.
高级语言: JavaScript
项目地址: git://github.com/pldin601/bookshelf-cls-transaction.git
创建时间: 2017-10-11T21:22:15Z
项目社区:https://github.com/pldin601/bookshelf-cls-transaction

开源协议:MIT License

下载


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:

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

With this plugin:

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

Installation

Install with npm:

  1. npm i bookshelf-cls-transaction

Add plugin to your bookshelf:

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