From 97948a46b4b5da08c64393fda592f2b5f8644d64 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 20 Apr 2023 16:29:57 +0800 Subject: [PATCH] refactor(nocodb): move to addTypeCastConfig --- .../nocodb-nest/src/utils/NcConfigFactory.ts | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/nocodb-nest/src/utils/NcConfigFactory.ts b/packages/nocodb-nest/src/utils/NcConfigFactory.ts index a42a1c18fb..0e9a5c9714 100644 --- a/packages/nocodb-nest/src/utils/NcConfigFactory.ts +++ b/packages/nocodb-nest/src/utils/NcConfigFactory.ts @@ -236,12 +236,10 @@ export default class NcConfigFactory { acquireConnectionTimeout: 600000, } as any; - if (url.protocol.startsWith('mysql')) { - dbConfig.connection = { - ...dbConfig.connection, - ...this.mysqlConnectionTypeCastConfig, - }; - } + dbConfig.connection = this.addTypeCastConfig( + url.protocol, + dbConfig.connection, + ); if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { dbConfig.connection.ssl = true; @@ -304,6 +302,16 @@ export default class NcConfigFactory { .replace(/[ -]/g, '_');*/ } + private static addTypeCastConfig(clientType: string, connection) { + if (clientType.startsWith('mysql')) { + connection = { + ...connection, + ...this.mysqlConnectionTypeCastConfig, + }; + } + return connection; + } + static async metaUrlToDbConfig(urlString) { const url = new URL(urlString); @@ -356,12 +364,10 @@ export default class NcConfigFactory { : {}), }; - if (url.protocol.startsWith('mysql')) { - dbConfig.connection = { - ...dbConfig.connection, - ...this.mysqlConnectionTypeCastConfig, - }; - } + dbConfig.connection = this.addTypeCastConfig( + url.protocol, + dbConfig.connection, + ); if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { dbConfig.connection.ssl = true; @@ -526,12 +532,10 @@ export default class NcConfigFactory { }; } - if (dbConfig.client.startsWith('mysql')) { - dbConfig.connection = { - ...dbConfig.connection, - ...this.mysqlConnectionTypeCastConfig, - }; - } + dbConfig.connection = this.addTypeCastConfig( + dbConfig.client, + dbConfig.connection, + ); // todo: const key = '';