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

koa-sequelize-transaction

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

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

app.use(errorHandler);
app.use(require('koa-sequelize-transaction')({
  // 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)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 2
Dependencies (2)
Dev Dependencies (12)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |