Wrap all koa calls in a transaction
Last updated 3 years ago by mickhansen .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install koa-sequelize-transaction 
SYNC missed versions from official npm registry.


Automatically manages the CLS namespace for ssacl/sequelize allowing you to simply do:

var _ = require('koa-route')
  , koa = require('koa')
  , app = koa();

  // pass an instance of sequelize
  sequelize: sequelize

app.use(_.post('/pets', function *() {
  // Both calls are automatically in the same transaction
  var pet = yield Pet.create({});
  yield pet.addOwner(this.actor);

koa-sequelize-transaction will ensure that any Sequelize calls in subsequent koa middleware will be scoped to the same transaction. commit/rollback will automatically be handled, you should handle any errors (on rollback) in your errorhandler and otherwise assume the transaction will succeed in your code (send a response).

Note if already using sequelize with CLS, it will automatically use that namespace instead of generating it's own.

Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 3
Dependencies (2)
Dev Dependencies (12)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |