Browse Source

feat: raw property for bulk data update

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest
mertmit 1 year ago
parent
commit
e447b422c7
  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

@ -2167,12 +2167,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 = [];
@ -2180,13 +2185,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 });
@ -2201,11 +2206,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) {

3
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 }],
});
}

Loading…
Cancel
Save