@nicheeeer/prisma-transaction
Version:
## Introduction `prisma-transaction` is a library that provides a simple way to use transactions in Prisma within NestJS using decorators. \ It simplifies handling transactions and ensures consistency across services by utilizing `AsyncLocalStorage` to m
47 lines • 1.89 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManualTransaction = void 0;
class ManualTransaction {
constructor(transaction) {
this.transaction = transaction;
}
get client() {
return this.transaction;
}
setTransaction(commit, rollback) {
this._commit = commit;
this._rollback = rollback;
}
commit() {
return __awaiter(this, void 0, void 0, function* () {
if (!this._commit || typeof this._commit !== 'function')
throw Error('Transaction commit not set');
this._commit();
yield this._waiter;
});
}
rollback(error) {
return __awaiter(this, void 0, void 0, function* () {
if (!this._rollback || typeof this._rollback !== 'function')
throw Error('Transaction rollback not set');
this._rollback(error);
yield this._waiter;
});
}
setWaiter(waiter) {
return __awaiter(this, void 0, void 0, function* () {
this._waiter = waiter;
});
}
}
exports.ManualTransaction = ManualTransaction;
//# sourceMappingURL=manual-transaction.js.map