egg-sequelize-autotrx
Advanced tools
Comparing version 0.0.13 to 0.0.14
module.exports = (options, app) => async (ctx, next) => { | ||
// console.log('my plugin', options) | ||
// console.log('app.config', app.config) | ||
const { namespace } = app.config.sequelizeAutotrx | ||
@@ -10,3 +6,3 @@ const sequelizeConfig = app.config.sequelize | ||
if (sequelizeConfig.datasources) { // multiple datasources | ||
console.log('--- multipe ') | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] multiple database case`) | ||
sequelizeConfig.datasources.forEach(datasource => { | ||
@@ -16,3 +12,3 @@ inject(ctx, getDelegate(datasource), namespace) | ||
} else { // single datasource | ||
console.log('--- single ') | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] single database case`) | ||
inject(ctx, getDelegate(sequelizeConfig), namespace) | ||
@@ -28,3 +24,2 @@ } | ||
const inject = (ctx, delegate, namespace) => { | ||
console.log('----- inject', delegate) | ||
const model = ctx[delegate] | ||
@@ -38,6 +33,6 @@ const { app } = ctx | ||
if (transaction) { | ||
app.loggers.appLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call injected transaction method`) | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call injected transaction method`) | ||
return oldTrx.call(model, { transaction }, task) | ||
} else { | ||
app.loggers.appLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call original transaction method`) | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call original transaction method`) | ||
return oldTrx.call(model, task) | ||
@@ -47,4 +42,4 @@ } | ||
model.transaction.__injected = true | ||
app.loggers.appLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction is injected`) | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction is injected`) | ||
} | ||
} |
{ | ||
"name": "egg-sequelize-autotrx", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"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
8746
51