strapi/packages/core/database/lib/transaction-context.js

26 lines
433 B
JavaScript
Raw Normal View History

2022-09-12 15:24:53 +02:00
'use strict';
const { AsyncLocalStorage } = require('async_hooks');
const storage = new AsyncLocalStorage();
const transactionCtx = {
async run(store, cb) {
return storage.run({ trx: store }, cb);
2022-09-12 15:24:53 +02:00
},
get() {
const store = storage.getStore();
return store?.trx;
},
clear() {
const store = storage.getStore();
if (store?.trx) {
store.trx = null;
}
2022-09-12 15:24:53 +02:00
},
};
module.exports = transactionCtx;