Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-sequelize-autotrx

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-sequelize-autotrx - npm Package Compare versions

Comparing version 0.0.19 to 0.0.20

4

app/middleware/transaction.js

@@ -27,7 +27,5 @@ module.exports = (options, app) => async (ctx, next) => {

const namespace = model.constructor._cls
console.log('--> ', namespace)
if (!namespace) {
console.log('!!! !!!! no namespace')
throw new Error(`[egg-sequelize-autotrx] needs CLS enabled in sequelize, but CLS namespace is not found under ${delegate} datasource`)
throw new Error(`[egg-sequelize-autotrx] needs CLS enabled in sequelize, but CLS namespace is not found under ctx.${delegate} datasource`)
}

@@ -34,0 +32,0 @@

{
"name": "egg-sequelize-autotrx",
"version": "0.0.19",
"version": "0.0.20",
"description": "Auto transaction based on cls-hooked for egg-sequelize plugin",

@@ -5,0 +5,0 @@ "eggPlugin": {

@@ -23,6 +23,8 @@ # egg-sequelize-autotrx

<!--
Description here.
-->
This plugin helps to do transaction auto pass down and solve the nested transaction issue.
## Problems
TODO desc the case with code ...
## Install

@@ -36,3 +38,27 @@

enable CLS of sequelize:
```js
// config.xx.js
const mySequelize = require('sequelize')
const clsNamespace = require('cls-hooked').createNamespace('your-namespace')
mySequelize.useCLS(clsNamespace)
module.exports = appInfo => {
const config = exports = {}
// single datasource case
config.sequelize = {
Sequelize: mySequelize, // use customized sequelize. https://github.com/eggjs/egg-sequelize#customize-sequelize
dialect: '',
// ...
}
// for multiple datasource, you need setup CLS of each your specific sequelize with different namespaces. https://github.com/eggjs/egg-sequelize#multiple-datasources
}
```
enable sequelize-autotrx plugin:
```js
// {app_root}/config/plugin.js

@@ -42,3 +68,3 @@ exports.sequelizeAutotrx = {

package: 'egg-sequelize-autotrx',
};
}
```

@@ -48,6 +74,8 @@

No configuration required:
```js
// {app_root}/config/config.default.js
exports.sequelizeAutotrx = {
};
}
```

@@ -59,4 +87,36 @@

<!-- example here -->
### single datasource
```js
// controller.js
async nestedTransactionTest () {
await this.ctx.model.transaction(async () => {
// if any of below operations failed, will rollback all
await this.createProject()
await this.nestedTrx()
await this.createUser()
})
}
async nestedTrxCanBeExecAlone () {
await this.nestedTrx()
}
async createProject () {
await this.ctx.model.Project.create()
}
async createUser () {
await this.ctx.model.User.create()
}
async nestedTrx () {
await this.ctx.model.transaction(async () => {
// other model operations
})
}
```
### multiple datasource
## Questions & Suggestions

@@ -63,0 +123,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc