egg-sequelize-autotrx
Advanced tools
Comparing version 0.0.15 to 0.0.16
module.exports = (options, app) => async (ctx, next) => { | ||
const { namespace } = app.config.sequelizeAutotrx | ||
const sequelizeConfig = app.config.sequelize | ||
@@ -8,7 +7,7 @@ | ||
sequelizeConfig.datasources.forEach(datasource => { | ||
inject(ctx, getDelegate(datasource), namespace) | ||
inject(ctx, getDelegate(datasource)) | ||
}) | ||
} else { // single datasource | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] single database case`) | ||
inject(ctx, getDelegate(sequelizeConfig), namespace) | ||
inject(ctx, getDelegate(sequelizeConfig)) | ||
} | ||
@@ -22,13 +21,14 @@ | ||
const inject = (ctx, delegate, namespace) => { | ||
const inject = (ctx, delegate) => { | ||
const { app } = ctx | ||
const model = ctx[delegate] | ||
const { app } = ctx | ||
console.log('------', model.constructor) | ||
console.log('------ _cls', model.constructor._cls) | ||
// https://github.com/sequelize/sequelize/blob/master/lib/sequelize.js#L1044 | ||
// namespace has to get from _cls, otherwise it will have issue for multiple datasources case | ||
const namespace = model.constructor._cls | ||
if (!model.transaction.__injected) { | ||
const oldTrx = model.transaction | ||
model.transaction = async task => { | ||
let transaction = namespace.get('transaction') | ||
const transaction = namespace.get('transaction') | ||
if (transaction) { | ||
@@ -35,0 +35,0 @@ app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call injected transaction method`) |
{ | ||
"name": "egg-sequelize-autotrx", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Auto transaction based on cls-hooked for egg-sequelize plugin", | ||
@@ -5,0 +5,0 @@ "eggPlugin": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8884