From d6a0715156908aec87bcb06bb1b7465837bba415 Mon Sep 17 00:00:00 2001 From: Dmitry Leontev Date: Tue, 31 Jan 2023 12:15:51 +0300 Subject: [PATCH] feat(cubejs-server-core): add dbType to dataSources --- packages/cubejs-api-gateway/test/index.test.ts | 2 +- packages/cubejs-api-gateway/test/mocks.ts | 2 +- packages/cubejs-server-core/src/core/CompilerApi.js | 3 ++- packages/cubejs-server-core/test/unit/index.test.ts | 6 +++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/cubejs-api-gateway/test/index.test.ts b/packages/cubejs-api-gateway/test/index.test.ts index ae255fd859bf1..8a29ec7ad6da9 100644 --- a/packages/cubejs-api-gateway/test/index.test.ts +++ b/packages/cubejs-api-gateway/test/index.test.ts @@ -592,7 +592,7 @@ describe('API Gateway', () => { } }] }, - { route: 'data-sources', successResult: { dataSources: ['default'] } }, + { route: 'data-sources', successResult: { dataSources: [{ dataSource: 'default', dbType: 'postgres' }] } }, ]; testConfigs.forEach((config) => { diff --git a/packages/cubejs-api-gateway/test/mocks.ts b/packages/cubejs-api-gateway/test/mocks.ts index 739638a032aa5..a95d5104d0f90 100644 --- a/packages/cubejs-api-gateway/test/mocks.ts +++ b/packages/cubejs-api-gateway/test/mocks.ts @@ -143,7 +143,7 @@ export const compilerApi = jest.fn().mockImplementation(() => ({ async dataSources() { return { - dataSources: ['default'] + dataSources: [{ dataSource: 'default', dbType: 'postgres' }] }; }, })); diff --git a/packages/cubejs-server-core/src/core/CompilerApi.js b/packages/cubejs-server-core/src/core/CompilerApi.js index d5c1f6be21bb5..90050144a0237 100644 --- a/packages/cubejs-server-core/src/core/CompilerApi.js +++ b/packages/cubejs-server-core/src/core/CompilerApi.js @@ -232,7 +232,8 @@ export class CompilerApi { dataSources.map(async (dataSource) => { try { await orchestratorApi.driverFactory(dataSource); - return dataSource; + const dbType = await this.getDbType(dataSource); + return { dataSource, dbType }; } catch (err) { return null; } diff --git a/packages/cubejs-server-core/test/unit/index.test.ts b/packages/cubejs-server-core/test/unit/index.test.ts index 8098ff2ef7469..21c37774aff54 100644 --- a/packages/cubejs-server-core/test/unit/index.test.ts +++ b/packages/cubejs-server-core/test/unit/index.test.ts @@ -414,7 +414,11 @@ describe('index.test', () => { }); expect(dataSources).toHaveProperty('dataSources'); - expect(dataSources.dataSources).toEqual(['main']); + expect(dataSources.dataSources).toEqual([{ + dataSource: 'main', + dbType: 'mysql', + }]); + expect(dataSourcesSpy).toHaveBeenCalled(); dataSourcesSpy.mockClear(); });