From 05f27bbaeedd6210db2de6ac51271b707d74e7ac Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 13 Apr 2023 21:15:58 +0530 Subject: [PATCH] fix: transactional instance creation of metaService Signed-off-by: Pranav C --- packages/nocodb-nest/src/meta/meta.service.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/nocodb-nest/src/meta/meta.service.ts b/packages/nocodb-nest/src/meta/meta.service.ts index f9c32fd5c9..ea62acc863 100644 --- a/packages/nocodb-nest/src/meta/meta.service.ts +++ b/packages/nocodb-nest/src/meta/meta.service.ts @@ -3,8 +3,8 @@ import { Inject, Injectable, OnApplicationBootstrap, - OnModuleInit, -} from '@nestjs/common'; + OnModuleInit, Optional, +} from '@nestjs/common' import { customAlphabet } from 'nanoid'; import CryptoJS from 'crypto-js'; @@ -186,10 +186,12 @@ const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14); @Injectable() export class MetaService { - constructor(private metaConnection: Connection) {} + constructor(private metaConnection: Connection, @Optional() trx = null) { + this.trx = trx; + } public get connection() { - return this.metaConnection.knexInstance; + return this.trx ?? this.metaConnection.knexInstance; } get knexConnection() { @@ -738,7 +740,7 @@ export class MetaService { this.trx = null; } - async startTransaction(): Promise { + async startTransaction(): Promise { const trx = await this.connection.transaction(); // todo: Extend transaction class to add our custom properties @@ -748,7 +750,7 @@ export class MetaService { }); // todo: tobe done - return this; //new NcMetaIOImpl(this.app, this.config, trx); + return new MetaService(this.metaConnection, trx); } async metaReset(