From 84e29413bedcb3ac8908946adf18fad44b54587f Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 7 Mar 2023 18:55:38 +0800 Subject: [PATCH] refactor(nocodb): add await --- .../src/lib/controllers/dbData/helpers.ts | 4 +- .../src/lib/controllers/dbData/oldData.ctl.ts | 12 +++--- .../publicControllers/publicDataExport.ctl.ts | 2 +- .../src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts | 2 +- packages/nocodb/src/lib/models/KanbanView.ts | 2 +- .../nocodb/src/lib/models/KanbanViewColumn.ts | 2 +- .../nocodb/src/lib/services/column.svc.ts | 12 +++--- .../src/lib/services/dbData/bulkData.ts | 2 +- .../services/dbData/dataAliasNested.svc.ts | 14 +++---- .../nocodb/src/lib/services/dbData/helpers.ts | 4 +- .../nocodb/src/lib/services/dbData/index.ts | 42 +++++++++---------- .../src/lib/services/public/publicData.svc.ts | 12 +++--- .../services/public/publicDataExport.svc.ts | 2 +- .../version-upgrader/ncAttachmentUpgrader.ts | 2 +- .../ncAttachmentUpgrader_0104002.ts | 2 +- packages/nocodb/tests/unit/factory/row.ts | 2 +- .../unit/model/tests/baseModelSql.test.ts | 8 ++-- 17 files changed, 63 insertions(+), 63 deletions(-) diff --git a/packages/nocodb/src/lib/controllers/dbData/helpers.ts b/packages/nocodb/src/lib/controllers/dbData/helpers.ts index 2ca5cd17e1..6e49638538 100644 --- a/packages/nocodb/src/lib/controllers/dbData/helpers.ts +++ b/packages/nocodb/src/lib/controllers/dbData/helpers.ts @@ -57,7 +57,7 @@ export async function extractXlsxData(param: { const baseModel = await Model.getBaseModelSQL({ id: view.model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const { offset, dbRows, elapsed } = await dataService.getDbRows({ @@ -92,7 +92,7 @@ export async function extractCsvData(view: View, req: Request) { const baseModel = await Model.getBaseModelSQL({ id: view.model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const { offset, dbRows, elapsed } = await dataService.getDbRows({ diff --git a/packages/nocodb/src/lib/controllers/dbData/oldData.ctl.ts b/packages/nocodb/src/lib/controllers/dbData/oldData.ctl.ts index 3492ff7361..51cdbe51c4 100644 --- a/packages/nocodb/src/lib/controllers/dbData/oldData.ctl.ts +++ b/packages/nocodb/src/lib/controllers/dbData/oldData.ctl.ts @@ -17,7 +17,7 @@ export async function dataList(req: Request, res: Response) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const requestObj = await getAst({ @@ -50,7 +50,7 @@ export async function dataCount(req: Request, res: Response) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const listArgs: any = { ...req.query }; @@ -73,7 +73,7 @@ async function dataInsert(req: Request, res: Response) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); res.json(await baseModel.insert(req.body, null, req)); @@ -86,7 +86,7 @@ async function dataUpdate(req: Request, res: Response) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); res.json(await baseModel.updateByPk(req.params.rowId, req.body, null, req)); @@ -98,7 +98,7 @@ async function dataDelete(req: Request, res: Response) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); res.json(await baseModel.delByPk(req.params.rowId, null, req)); @@ -128,7 +128,7 @@ async function dataRead(req: Request, res: Response) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); res.json( diff --git a/packages/nocodb/src/lib/controllers/publicControllers/publicDataExport.ctl.ts b/packages/nocodb/src/lib/controllers/publicControllers/publicDataExport.ctl.ts index cc677d6ab6..6afec3ef35 100644 --- a/packages/nocodb/src/lib/controllers/publicControllers/publicDataExport.ctl.ts +++ b/packages/nocodb/src/lib/controllers/publicControllers/publicDataExport.ctl.ts @@ -138,7 +138,7 @@ async function getDbRows(model, view: View, req: Request) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const requestObj = await getAst({ diff --git a/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts b/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts index 82852fed52..bbb9210a48 100644 --- a/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts +++ b/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts @@ -34,7 +34,7 @@ export default class SqlMgrv2Trans extends SqlMgrv2 { } public async startTransaction(base: Base) { - const knex: XKnex = NcConnectionMgrv2.get(base); + const knex: XKnex = await NcConnectionMgrv2.get(base); this.trx = await knex.transaction(); } diff --git a/packages/nocodb/src/lib/models/KanbanView.ts b/packages/nocodb/src/lib/models/KanbanView.ts index b5ec87d85e..562563a97d 100644 --- a/packages/nocodb/src/lib/models/KanbanView.ts +++ b/packages/nocodb/src/lib/models/KanbanView.ts @@ -1,5 +1,5 @@ import Noco from '../Noco'; -import { BoolType, KanbanType, MetaType, UITypes } from 'nocodb-sdk'; +import type { BoolType, KanbanType, MetaType, UITypes } from 'nocodb-sdk'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import View from './View'; import NocoCache from '../cache/NocoCache'; diff --git a/packages/nocodb/src/lib/models/KanbanViewColumn.ts b/packages/nocodb/src/lib/models/KanbanViewColumn.ts index 3f0b22bef4..026471e16b 100644 --- a/packages/nocodb/src/lib/models/KanbanViewColumn.ts +++ b/packages/nocodb/src/lib/models/KanbanViewColumn.ts @@ -3,7 +3,7 @@ import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import View from './View'; import NocoCache from '../cache/NocoCache'; import { extractProps } from '../meta/helpers/extractProps'; -import { BoolType, KanbanColumnType } from 'nocodb-sdk'; +import type { BoolType, KanbanColumnType } from 'nocodb-sdk'; export default class KanbanViewColumn implements KanbanColumnType { id: string; diff --git a/packages/nocodb/src/lib/services/column.svc.ts b/packages/nocodb/src/lib/services/column.svc.ts index 1609f02fe8..7291b9dbc4 100644 --- a/packages/nocodb/src/lib/services/column.svc.ts +++ b/packages/nocodb/src/lib/services/column.svc.ts @@ -127,7 +127,7 @@ export async function columnUpdate(param: { try { // test the query to see if it is valid in db level - const dbDriver = NcConnectionMgrv2.get(base); + const dbDriver = await NcConnectionMgrv2.get(base); await formulaQueryBuilderv2(colBody.formula, null, dbDriver, table); } catch (e) { console.error(e); @@ -171,12 +171,12 @@ export async function columnUpdate(param: { const baseModel = await Model.getBaseModelSQL({ id: table.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); if (colBody.colOptions?.options) { const supportedDrivers = ['mysql', 'mysql2', 'pg', 'mssql', 'sqlite3']; - const dbDriver = NcConnectionMgrv2.get(base); + const dbDriver = await NcConnectionMgrv2.get(base); const driverType = dbDriver.clientType(); // MultiSelect to SingleSelect @@ -849,7 +849,7 @@ export async function columnAdd(param: { const project = await base.getProject(); if (param.column.title || param.column.column_name) { - const dbDriver = NcConnectionMgrv2.get(base); + const dbDriver = await NcConnectionMgrv2.get(base); const sqlClientType = dbDriver.clientType(); @@ -932,7 +932,7 @@ export async function columnAdd(param: { try { // test the query to see if it is valid in db level - const dbDriver = NcConnectionMgrv2.get(base); + const dbDriver = await NcConnectionMgrv2.get(base); await formulaQueryBuilderv2(colBody.formula, null, dbDriver, table); } catch (e) { console.error(e); @@ -958,7 +958,7 @@ export async function columnAdd(param: { if ( [UITypes.SingleSelect, UITypes.MultiSelect].includes(colBody.uidt) ) { - const dbDriver = NcConnectionMgrv2.get(base); + const dbDriver = await NcConnectionMgrv2.get(base); const driverType = dbDriver.clientType(); const optionTitles = colBody.colOptions.options.map((el) => el.title.replace(/'/g, "''") diff --git a/packages/nocodb/src/lib/services/dbData/bulkData.ts b/packages/nocodb/src/lib/services/dbData/bulkData.ts index 2ac6b5a20b..8c4c84c01c 100644 --- a/packages/nocodb/src/lib/services/dbData/bulkData.ts +++ b/packages/nocodb/src/lib/services/dbData/bulkData.ts @@ -27,7 +27,7 @@ export async function executeBulkOperation( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await baseModel[param.operation].apply(null, param.options); } diff --git a/packages/nocodb/src/lib/services/dbData/dataAliasNested.svc.ts b/packages/nocodb/src/lib/services/dbData/dataAliasNested.svc.ts index 20959d15fa..0994b1818c 100644 --- a/packages/nocodb/src/lib/services/dbData/dataAliasNested.svc.ts +++ b/packages/nocodb/src/lib/services/dbData/dataAliasNested.svc.ts @@ -25,7 +25,7 @@ export async function mmList( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const column = await getColumnByIdOrName(param.columnName, model); @@ -63,7 +63,7 @@ export async function mmExcludedList( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const column = await getColumnByIdOrName(param.columnName, model); @@ -105,7 +105,7 @@ export async function hmExcludedList( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const column = await getColumnByIdOrName(param.columnName, model); @@ -147,7 +147,7 @@ export async function btExcludedList( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const column = await getColumnByIdOrName(param.columnName, model); @@ -191,7 +191,7 @@ export async function hmList( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const column = await getColumnByIdOrName(param.columnName, model); @@ -232,7 +232,7 @@ export async function relationDataRemove( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const column = await getColumnByIdOrName(param.columnName, model); @@ -265,7 +265,7 @@ export async function relationDataAdd( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const column = await getColumnByIdOrName(param.columnName, model); diff --git a/packages/nocodb/src/lib/services/dbData/helpers.ts b/packages/nocodb/src/lib/services/dbData/helpers.ts index 9654fc3dfc..54b8a3fe03 100644 --- a/packages/nocodb/src/lib/services/dbData/helpers.ts +++ b/packages/nocodb/src/lib/services/dbData/helpers.ts @@ -58,7 +58,7 @@ export async function extractXlsxData(view: View, req: Request) { const baseModel = await Model.getBaseModelSQL({ id: view.model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const { offset, dbRows, elapsed } = await getDbRows({ @@ -93,7 +93,7 @@ export async function extractCsvData(view: View, req: Request) { const baseModel = await Model.getBaseModelSQL({ id: view.model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const { offset, dbRows, elapsed } = await getDbRows({ diff --git a/packages/nocodb/src/lib/services/dbData/index.ts b/packages/nocodb/src/lib/services/dbData/index.ts index c125530352..e491726f78 100644 --- a/packages/nocodb/src/lib/services/dbData/index.ts +++ b/packages/nocodb/src/lib/services/dbData/index.ts @@ -30,7 +30,7 @@ export async function dataCount(param: PathParams & { query: any }) { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const countArgs: any = { ...param.query }; @@ -53,7 +53,7 @@ export async function dataInsert( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await baseModel.insert(param.body, null, param.cookie); @@ -68,7 +68,7 @@ export async function dataUpdate( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await baseModel.updateByPk( @@ -87,7 +87,7 @@ export async function dataDelete( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); // todo: Should have error http status code @@ -110,7 +110,7 @@ export async function getDataList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const requestObj = await getAst({ model, query, view }); @@ -158,7 +158,7 @@ export async function getFindOne(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const args: any = { ...query }; @@ -192,7 +192,7 @@ export async function getDataGroupBy(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const listArgs: any = { ...query }; @@ -215,7 +215,7 @@ export async function dataRead( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const row = await baseModel.readByPk(param.rowId); @@ -242,7 +242,7 @@ export async function dataExist( const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await baseModel.exist(param.rowId); @@ -275,7 +275,7 @@ export async function getGroupedDataList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const requestObj = await getAst({ model, query, view }); @@ -353,7 +353,7 @@ export async function mmList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const key = `${model.title}List`; @@ -411,7 +411,7 @@ export async function mmExcludedList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const key = 'List'; @@ -472,7 +472,7 @@ export async function hmExcludedList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const key = 'List'; @@ -533,7 +533,7 @@ export async function btExcludedList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const key = 'List'; @@ -594,7 +594,7 @@ export async function hmList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const key = `${model.title}List`; @@ -646,7 +646,7 @@ export async function dataReadByViewId(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await nocoExecute( @@ -677,7 +677,7 @@ export async function dataInsertByViewId(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await baseModel.insert(param.body, null, param.cookie); @@ -698,7 +698,7 @@ export async function dataUpdateByViewId(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await baseModel.updateByPk( @@ -723,7 +723,7 @@ export async function dataDeleteByViewId(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); return await baseModel.delByPk(param.rowId, null, param.cookie); @@ -749,7 +749,7 @@ export async function relationDataDelete(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); await baseModel.removeChild({ @@ -782,7 +782,7 @@ export async function relationDataAdd(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); await baseModel.addChild({ diff --git a/packages/nocodb/src/lib/services/public/publicData.svc.ts b/packages/nocodb/src/lib/services/public/publicData.svc.ts index e361b7cbff..41c5b8e61b 100644 --- a/packages/nocodb/src/lib/services/public/publicData.svc.ts +++ b/packages/nocodb/src/lib/services/public/publicData.svc.ts @@ -49,7 +49,7 @@ export async function dataList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const listArgs: any = { ...param.query }; @@ -130,7 +130,7 @@ async function getGroupedDataList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const requestObj = await getAst({ model, query: param.query, view }); @@ -208,7 +208,7 @@ export async function dataInsert(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); await view.getViewWithInfo(); @@ -306,7 +306,7 @@ export async function relDataList(param: { const baseModel = await Model.getBaseModelSQL({ id: model.id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const requestObj = await getAst({ @@ -362,7 +362,7 @@ export async function publicMmList(param: { const baseModel = await Model.getBaseModelSQL({ id: view.fk_model_id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const key = `List`; @@ -427,7 +427,7 @@ export async function publicHmList(param: { const baseModel = await Model.getBaseModelSQL({ id: view.fk_model_id, viewId: view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const key = `List`; diff --git a/packages/nocodb/src/lib/services/public/publicDataExport.svc.ts b/packages/nocodb/src/lib/services/public/publicDataExport.svc.ts index 900dd3ed88..a35c18ef50 100644 --- a/packages/nocodb/src/lib/services/public/publicDataExport.svc.ts +++ b/packages/nocodb/src/lib/services/public/publicDataExport.svc.ts @@ -45,7 +45,7 @@ export async function getDbRows(param: { const baseModel = await Model.getBaseModelSQL({ id: param.model.id, viewId: param.view?.id, - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), }); const requestObj = await getAst({ diff --git a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts index f5c1393b3a..03c9913c09 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts @@ -66,7 +66,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { const knex: Knex = base.is_meta ? ncMeta.knexConnection - : NcConnectionMgrv2.get(base); + : await NcConnectionMgrv2.get(base); const models = await base.getModels(ncMeta); // used in timeout error message diff --git a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts index b732a51970..13ef464913 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts @@ -58,7 +58,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { const knex: Knex = base.is_meta ? ncMeta.knexConnection - : NcConnectionMgrv2.get(base); + : await NcConnectionMgrv2.get(base); const models = await base.getModels(ncMeta); // used in timeout error message diff --git a/packages/nocodb/tests/unit/factory/row.ts b/packages/nocodb/tests/unit/factory/row.ts index 6c26c39ef8..490272f4bf 100644 --- a/packages/nocodb/tests/unit/factory/row.ts +++ b/packages/nocodb/tests/unit/factory/row.ts @@ -218,7 +218,7 @@ const listRow = async ({ const bases = await project.getBases(); const baseModel = await Model.getBaseModelSQL({ id: table.id, - dbDriver: NcConnectionMgrv2.get(bases[0]!), + dbDriver: await NcConnectionMgrv2.get(bases[0]!), }); const ignorePagination = !options; diff --git a/packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts b/packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts index 791711921b..46f6d81c8c 100644 --- a/packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts +++ b/packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts @@ -31,7 +31,7 @@ function baseModelSqlTests() { const base = await Base.get(table.base_id); baseModelSql = new BaseModelSqlv2({ - dbDriver: NcConnectionMgrv2.get(base), + dbDriver: await NcConnectionMgrv2.get(base), model: table, view }) @@ -347,7 +347,7 @@ function baseModelSqlTests() { ); const childBaseModel = new BaseModelSqlv2({ - dbDriver: NcConnectionMgrv2.get(await Base.get(table.base_id)), + dbDriver: await NcConnectionMgrv2.get(await Base.get(table.base_id)), model: childTable, view }) @@ -406,7 +406,7 @@ function baseModelSqlTests() { }); const childBaseModel = new BaseModelSqlv2({ - dbDriver: NcConnectionMgrv2.get(await Base.get(table.base_id)), + dbDriver: await NcConnectionMgrv2.get(await Base.get(table.base_id)), model: childTable, view }) @@ -473,7 +473,7 @@ function baseModelSqlTests() { }); const childBaseModel = new BaseModelSqlv2({ - dbDriver: NcConnectionMgrv2.get(await Base.get(table.base_id)), + dbDriver: await NcConnectionMgrv2.get(await Base.get(table.base_id)), model: childTable, view })