From e6563ba892c43fc9878d08bc65bb7f4782eeebf3 Mon Sep 17 00:00:00 2001 From: mertmit Date: Thu, 4 May 2023 15:29:03 +0300 Subject: [PATCH] feat: raw property for bulk data update Signed-off-by: mertmit --- packages/nocodb-nest/src/db/BaseModelSqlv2.ts | 26 ++++++++++++------- .../src/services/bulk-data-alias.service.ts | 3 ++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/nocodb-nest/src/db/BaseModelSqlv2.ts b/packages/nocodb-nest/src/db/BaseModelSqlv2.ts index 377dc50124..7c4ec482ff 100644 --- a/packages/nocodb-nest/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb-nest/src/db/BaseModelSqlv2.ts @@ -2166,12 +2166,17 @@ class BaseModelSqlv2 { } } - async bulkUpdate(datas: any[], { cookie }: { cookie?: any } = {}) { + async bulkUpdate( + datas: any[], + { cookie, raw = false }: { cookie?: any; raw?: boolean } = {}, + ) { let transaction; try { - const updateDatas = await Promise.all( - datas.map((d) => this.model.mapAliasToColumn(d)), - ); + if (raw) await this.model.getColumns(); + + const updateDatas = raw + ? datas + : await Promise.all(datas.map((d) => this.model.mapAliasToColumn(d))); const prevData = []; const newData = []; @@ -2179,13 +2184,13 @@ class BaseModelSqlv2 { const toBeUpdated = []; const res = []; for (const d of updateDatas) { - await this.validate(d); + if (!raw) await this.validate(d); const pkValues = await this._extractPksValues(d); if (!pkValues) { // pk not specified - bypass continue; } - prevData.push(await this.readByPk(pkValues)); + if (!raw) prevData.push(await this.readByPk(pkValues)); const wherePk = await this._wherePk(pkValues); res.push(wherePk); toBeUpdated.push({ d, wherePk }); @@ -2200,11 +2205,14 @@ class BaseModelSqlv2 { await transaction.commit(); - for (const pkValues of updatePkValues) { - newData.push(await this.readByPk(pkValues)); + if (!raw) { + for (const pkValues of updatePkValues) { + newData.push(await this.readByPk(pkValues)); + } } - await this.afterBulkUpdate(prevData, newData, this.dbDriver, cookie); + if (!raw) + await this.afterBulkUpdate(prevData, newData, this.dbDriver, cookie); return res; } catch (e) { diff --git a/packages/nocodb-nest/src/services/bulk-data-alias.service.ts b/packages/nocodb-nest/src/services/bulk-data-alias.service.ts index d61556254c..cc77470b23 100644 --- a/packages/nocodb-nest/src/services/bulk-data-alias.service.ts +++ b/packages/nocodb-nest/src/services/bulk-data-alias.service.ts @@ -68,12 +68,13 @@ export class BulkDataAliasService { param: PathParams & { body: any; cookie: any; + raw?: boolean; }, ) { return await this.executeBulkOperation({ ...param, operation: 'bulkUpdate', - options: [param.body, { cookie: param.cookie }], + options: [param.body, { cookie: param.cookie, raw: param.raw }], }); }