Browse Source

fix: bulk update logic

pull/5444/head
Wing-Kam Wong 1 year ago
parent
commit
4ecf601765
  1. 12
      packages/nocodb-nest/src/db/BaseModelSqlv2.ts

12
packages/nocodb-nest/src/db/BaseModelSqlv2.ts

@ -2149,12 +2149,10 @@ class BaseModelSqlv2 {
datas.map((d) => this.model.mapAliasToColumn(d)),
);
transaction = await this.dbDriver.transaction();
// await this.beforeUpdateb(updateDatas, transaction);
const prevData = [];
const newData = [];
const updatePkValues = [];
const toBeUpdated = [];
const res = [];
for (const d of updateDatas) {
await this.validate(d);
@ -2165,11 +2163,17 @@ class BaseModelSqlv2 {
}
prevData.push(await this.readByPk(pkValues));
const wherePk = await this._wherePk(pkValues);
await transaction(this.tnPath).update(d).where(wherePk);
res.push(wherePk);
toBeUpdated.push({ d, wherePk });
updatePkValues.push(pkValues);
}
transaction = await this.dbDriver.transaction();
for (const o of toBeUpdated) {
await transaction(this.tnPath).update(o.d).where(o.wherePk);
}
await transaction.commit();
for (const pkValues of updatePkValues) {

Loading…
Cancel
Save