Browse Source

feat: raw property for bulk data update

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest-dir-restructure
mertmit 2 years ago committed by starbirdtech383
parent
commit
e6563ba892
  1. 26
      packages/nocodb-nest/src/db/BaseModelSqlv2.ts
  2. 3
      packages/nocodb-nest/src/services/bulk-data-alias.service.ts

26
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; let transaction;
try { try {
const updateDatas = await Promise.all( if (raw) await this.model.getColumns();
datas.map((d) => this.model.mapAliasToColumn(d)),
); const updateDatas = raw
? datas
: await Promise.all(datas.map((d) => this.model.mapAliasToColumn(d)));
const prevData = []; const prevData = [];
const newData = []; const newData = [];
@ -2179,13 +2184,13 @@ class BaseModelSqlv2 {
const toBeUpdated = []; const toBeUpdated = [];
const res = []; const res = [];
for (const d of updateDatas) { for (const d of updateDatas) {
await this.validate(d); if (!raw) await this.validate(d);
const pkValues = await this._extractPksValues(d); const pkValues = await this._extractPksValues(d);
if (!pkValues) { if (!pkValues) {
// pk not specified - bypass // pk not specified - bypass
continue; continue;
} }
prevData.push(await this.readByPk(pkValues)); if (!raw) prevData.push(await this.readByPk(pkValues));
const wherePk = await this._wherePk(pkValues); const wherePk = await this._wherePk(pkValues);
res.push(wherePk); res.push(wherePk);
toBeUpdated.push({ d, wherePk }); toBeUpdated.push({ d, wherePk });
@ -2200,11 +2205,14 @@ class BaseModelSqlv2 {
await transaction.commit(); await transaction.commit();
for (const pkValues of updatePkValues) { if (!raw) {
newData.push(await this.readByPk(pkValues)); 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; return res;
} catch (e) { } catch (e) {

3
packages/nocodb-nest/src/services/bulk-data-alias.service.ts

@ -68,12 +68,13 @@ export class BulkDataAliasService {
param: PathParams & { param: PathParams & {
body: any; body: any;
cookie: any; cookie: any;
raw?: boolean;
}, },
) { ) {
return await this.executeBulkOperation({ return await this.executeBulkOperation({
...param, ...param,
operation: 'bulkUpdate', operation: 'bulkUpdate',
options: [param.body, { cookie: param.cookie }], options: [param.body, { cookie: param.cookie, raw: param.raw }],
}); });
} }

Loading…
Cancel
Save