From 9d7ae0f9a7fba0278a1b9b64927328e61f4fa5bf Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 13 Apr 2023 20:20:21 +0530 Subject: [PATCH] fix: avoid duplicate meta connection creation Signed-off-by: Pranav C --- packages/nocodb-nest/src/connection/connection.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/nocodb-nest/src/connection/connection.ts b/packages/nocodb-nest/src/connection/connection.ts index 136075aad7..9fafec9b56 100644 --- a/packages/nocodb-nest/src/connection/connection.ts +++ b/packages/nocodb-nest/src/connection/connection.ts @@ -8,11 +8,11 @@ import NcConfigFactory from '../utils/NcConfigFactory' scope: Scope.DEFAULT }) export class Connection { - private knex: knex.Knex; + private static knex: knex.Knex; private _config: any; get knexInstance(): knex.Knex { - return this.knex; + return Connection.knex; } get config(): knex.Knex { @@ -22,9 +22,11 @@ export class Connection { // init metadb connection async init(): Promise { this._config = await NcConfigFactory.make(); - this.knex = XKnex({ - ...this._config.meta.db, - useNullAsDefault: true, - }); + if(!Connection.knex) { + Connection.knex = XKnex({ + ...this._config.meta.db, + useNullAsDefault: true, + }); + } } }