From def45f99d8c320f0e5728e7d33a56fcec99d62ed Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 7 Sep 2022 16:38:53 +0530 Subject: [PATCH] fix(gui-v2): add mariadb mysql mapping and add test for DATABASE_URL Signed-off-by: Pranav C --- .../__tests__/noco/NcConfigFactory.test.ts | 29 +++++++++++++++++++ .../nocodb/src/lib/utils/NcConfigFactory.ts | 1 + 2 files changed, 30 insertions(+) diff --git a/packages/nocodb/src/__tests__/noco/NcConfigFactory.test.ts b/packages/nocodb/src/__tests__/noco/NcConfigFactory.test.ts index 10956a2188..04394bff8d 100644 --- a/packages/nocodb/src/__tests__/noco/NcConfigFactory.test.ts +++ b/packages/nocodb/src/__tests__/noco/NcConfigFactory.test.ts @@ -38,6 +38,35 @@ describe('Config Factory Tests', () => { expect(dbConfig).to.deep.equal(rest); done(); }); + + it('Generate config from DATABASE_URL', function (done) { + // postgres url + const ncDbUrl = NcConfigFactory.extractXcUrlFromJdbc( + 'postgres://username:password@host:5432/db' + ); + expect(ncDbUrl).to.be.equal('pg://host:5432?u=username&p=password&d=db&'); + + // postgres url without port + const ncDbUrl1 = NcConfigFactory.extractXcUrlFromJdbc( + 'postgres://username:password@host/db' + ); + expect(ncDbUrl1).to.be.equal('pg://host:5432?u=username&p=password&d=db&'); + + // mysql url + const ncDbUrl2 = NcConfigFactory.extractXcUrlFromJdbc( + 'jdbc:mysql://localhost/sample_db' + ); + expect(ncDbUrl2).to.be.equal('mysql2://localhost:3306?d=sample_db&'); + + // mariadb url + const ncDbUrl3 = NcConfigFactory.extractXcUrlFromJdbc( + 'jdbc:mariadb://localhost/sample_db' + ); + expect(ncDbUrl3).to.be.equal('mysql2://localhost:3306?d=sample_db&'); + + done(); + }); + it('Connection string with nested property', function (done) { const dbConfig = NcConfigFactory.metaUrlToDbConfig( `pg://localhost:5432?u=postgres&p=xgene&d=abcde&pool.min=1&pool.max=2&ssl.rejectUnauthorized=false` diff --git a/packages/nocodb/src/lib/utils/NcConfigFactory.ts b/packages/nocodb/src/lib/utils/NcConfigFactory.ts index b267322c8a..3cfc471ca7 100644 --- a/packages/nocodb/src/lib/utils/NcConfigFactory.ts +++ b/packages/nocodb/src/lib/utils/NcConfigFactory.ts @@ -20,6 +20,7 @@ const { const driverClientMapping = { mysql: 'mysql2', + mariadb: 'mysql2', postgres: 'pg', postgresql: 'pg', sqlite: 'sqlite3',