Browse Source

fix(nocodb): bulk update logic

pull/5349/head
Wing-Kam Wong 2 years ago
parent
commit
c6864de3d4
  1. 8
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

8
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1975,6 +1975,7 @@ class BaseModelSqlv2 {
// await this.beforeUpdateb(updateDatas, transaction); // await this.beforeUpdateb(updateDatas, transaction);
const prevData = []; const prevData = [];
const newData = []; const newData = [];
const updatePkValues = [];
const res = []; const res = [];
for (const d of updateDatas) { for (const d of updateDatas) {
await this.validate(d); await this.validate(d);
@ -1987,11 +1988,16 @@ class BaseModelSqlv2 {
const wherePk = await this._wherePk(pkValues); const wherePk = await this._wherePk(pkValues);
await transaction(this.tnPath).update(d).where(wherePk); await transaction(this.tnPath).update(d).where(wherePk);
res.push(wherePk); res.push(wherePk);
updatePkValues.push(pkValues);
}
transaction.commit();
for (const pkValues of updatePkValues) {
newData.push(await this.readByPk(pkValues)); newData.push(await this.readByPk(pkValues));
} }
await this.afterBulkUpdate(prevData, newData, this.dbDriver, cookie); await this.afterBulkUpdate(prevData, newData, this.dbDriver, cookie);
transaction.commit();
return res; return res;
} catch (e) { } catch (e) {

Loading…
Cancel
Save