Browse Source

refactor(nocodb): add await

pull/5262/head
Wing-Kam Wong 2 years ago
parent
commit
84e29413be
  1. 4
      packages/nocodb/src/lib/controllers/dbData/helpers.ts
  2. 12
      packages/nocodb/src/lib/controllers/dbData/oldData.ctl.ts
  3. 2
      packages/nocodb/src/lib/controllers/publicControllers/publicDataExport.ctl.ts
  4. 2
      packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts
  5. 2
      packages/nocodb/src/lib/models/KanbanView.ts
  6. 2
      packages/nocodb/src/lib/models/KanbanViewColumn.ts
  7. 12
      packages/nocodb/src/lib/services/column.svc.ts
  8. 2
      packages/nocodb/src/lib/services/dbData/bulkData.ts
  9. 14
      packages/nocodb/src/lib/services/dbData/dataAliasNested.svc.ts
  10. 4
      packages/nocodb/src/lib/services/dbData/helpers.ts
  11. 42
      packages/nocodb/src/lib/services/dbData/index.ts
  12. 12
      packages/nocodb/src/lib/services/public/publicData.svc.ts
  13. 2
      packages/nocodb/src/lib/services/public/publicDataExport.svc.ts
  14. 2
      packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts
  15. 2
      packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader_0104002.ts
  16. 2
      packages/nocodb/tests/unit/factory/row.ts
  17. 8
      packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts

4
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({

12
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(

2
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({

2
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();
}

2
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';

2
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;

12
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, "''")

2
packages/nocodb/src/lib/services/dbData/bulkData.ts

@ -27,7 +27,7 @@ export async function executeBulkOperation<T extends BulkOperation>(
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);
}

14
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);

4
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({

42
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({

12
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`;

2
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({

2
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

2
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

2
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;

8
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
})

Loading…
Cancel
Save