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.7 to 0.0.8

38

app/middleware/transaction.js

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

const { namespace } = app.config.sequelizeAutoTrx
const sequelizeConfig = app.config.sequelize
if (!ctx.model.transaction.__injected) {
const oldTrx = ctx.model.transaction
ctx.model.transaction = async task => {
if (sequelizeConfig.datasources) { // multiple datasources
sequelizeConfig.datasources.forEach(datasource => {
inject(ctx, getDelegate(datasource), namespace)
})
} else { // single datasource
inject(ctx, getDelegate(sequelizeConfig), namespace)
}
await next()
}
// refer: https://github.com/eggjs/egg-sequelize#multiple-datasources
const getDelegate = datasource => datasource.delegate || 'model'
const inject = (ctx, delegate, namespace) => {
const model = ctx[delegate]
if (!model.transaction.__injected) {
const oldTrx = model.transaction
model.transaction = async task => {
let transaction = namespace.get('transaction')
if (transaction) {
console.log('-- has parent trx')
return oldTrx.call(ctx.model, { transaction }, task)
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call injected transaction method`)
return oldTrx.call(model, { transaction }, task)
} else {
console.log('-- no parent trx')
return oldTrx.call(ctx.model, task)
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call original transaction method`)
return oldTrx.call(model, task)
}
}
ctx.model.transaction.__injected = true
console.log('ctx.model.transaction injected')
model.transaction.__injected = true
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction is injected`)
}
await next()
}
{
"name": "egg-sequelize-autotrx",
"version": "0.0.7",
"version": "0.0.8",
"description": "Auto transaction based on cls-hooked for egg-sequelize plugin",

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

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