strapi/packages/core/database/lib/transaction-context.js
2023-04-11 15:16:09 +02:00

19 lines
340 B
JavaScript

'use strict';
const { AsyncLocalStorage } = require('async_hooks');
const storage = new AsyncLocalStorage();
const transactionCtx = {
async run(store, cb) {
return storage.run(store, cb);
},
get() {
const trx = storage.getStore();
return trx?.isCompleted() ? undefined : trx;
},
};
module.exports = transactionCtx;