egg-sequelize-autotrx
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -34,10 +34,18 @@ module.exports = (options, app) => async (ctx, next) => { | ||
const oldTrx = model.transaction | ||
model.transaction = async task => { | ||
const transaction = namespace.get('transaction') | ||
if (transaction) { | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call injected transaction method`) | ||
return oldTrx.call(model, { transaction }, task) | ||
model.transaction = async (...args) => { | ||
if (args.length === 1) { // transaction(asyncTask) | ||
const task = args[0] | ||
const transaction = namespace.get('transaction') | ||
if (transaction) { | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction specified transaction`) | ||
return oldTrx.call(model, { transaction }, task) | ||
} else { | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction no specified transaction`) | ||
return oldTrx.call(model, task) | ||
} | ||
} else { | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call original transaction method`) | ||
return oldTrx.call(model, task) | ||
// for example: transaction({ transaction }, asyncTask) | ||
// will call original transaction function directly, without inject transaction in cls | ||
app.loggers.coreLogger.info(`[egg-sequelize-autotrx] ctx.[${delegate}].transaction call original method`) | ||
return oldTrx.call(model, ...args) | ||
} | ||
@@ -44,0 +52,0 @@ } |
{ | ||
"name": "egg-sequelize-autotrx", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "Auto transaction based on cls-hooked for egg-sequelize plugin", | ||
@@ -5,0 +5,0 @@ "eggPlugin": { |
12302
58