Browse Source

Merge pull request #5491 from nocodb/fix/bulk-update-transaction

fix(nocodb): bulk update transaction
pull/5494/head
Raju Udava 2 years ago committed by GitHub
parent
commit
88f92cf786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

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

@ -2117,12 +2117,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);
@ -2133,11 +2131,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