Browse Source

fix: transactional instance creation of metaService

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
05f27bbaee
  1. 14
      packages/nocodb-nest/src/meta/meta.service.ts

14
packages/nocodb-nest/src/meta/meta.service.ts

@ -3,8 +3,8 @@ import {
Inject, Inject,
Injectable, Injectable,
OnApplicationBootstrap, OnApplicationBootstrap,
OnModuleInit, OnModuleInit, Optional,
} from '@nestjs/common'; } from '@nestjs/common'
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
@ -186,10 +186,12 @@ const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);
@Injectable() @Injectable()
export class MetaService { export class MetaService {
constructor(private metaConnection: Connection) {} constructor(private metaConnection: Connection, @Optional() trx = null) {
this.trx = trx;
}
public get connection() { public get connection() {
return this.metaConnection.knexInstance; return this.trx ?? this.metaConnection.knexInstance;
} }
get knexConnection() { get knexConnection() {
@ -738,7 +740,7 @@ export class MetaService {
this.trx = null; this.trx = null;
} }
async startTransaction(): Promise<this> { async startTransaction(): Promise<MetaService> {
const trx = await this.connection.transaction(); const trx = await this.connection.transaction();
// todo: Extend transaction class to add our custom properties // todo: Extend transaction class to add our custom properties
@ -748,7 +750,7 @@ export class MetaService {
}); });
// todo: tobe done // todo: tobe done
return this; //new NcMetaIOImpl(this.app, this.config, trx); return new MetaService(this.metaConnection, trx);
} }
async metaReset( async metaReset(

Loading…
Cancel
Save