Browse Source

fix: bulk update logic

pull/5444/head
Wing-Kam Wong 2 years 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)), datas.map((d) => this.model.mapAliasToColumn(d)),
); );
transaction = await this.dbDriver.transaction();
// await this.beforeUpdateb(updateDatas, transaction);
const prevData = []; const prevData = [];
const newData = []; const newData = [];
const updatePkValues = []; const updatePkValues = [];
const toBeUpdated = [];
const res = []; const res = [];
for (const d of updateDatas) { for (const d of updateDatas) {
await this.validate(d); await this.validate(d);
@ -2165,11 +2163,17 @@ class BaseModelSqlv2 {
} }
prevData.push(await this.readByPk(pkValues)); prevData.push(await this.readByPk(pkValues));
const wherePk = await this._wherePk(pkValues); const wherePk = await this._wherePk(pkValues);
await transaction(this.tnPath).update(d).where(wherePk);
res.push(wherePk); res.push(wherePk);
toBeUpdated.push({ d, wherePk });
updatePkValues.push(pkValues); 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(); await transaction.commit();
for (const pkValues of updatePkValues) { for (const pkValues of updatePkValues) {

Loading…
Cancel
Save