Browse Source

fix: sqlite issues

pull/9788/head
DarkPhoenix2704 3 weeks ago
parent
commit
e8db699a92
No known key found for this signature in database
GPG Key ID: 3F76B10622A07849
  1. 22
      packages/nocodb/src/db/BaseModelSqlv2.ts

22
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -5326,8 +5326,6 @@ class BaseModelSqlv2 {
} }
} }
trx = await this.dbDriver.transaction();
// Check which records with PKs exist in the database // Check which records with PKs exist in the database
const existingRecords = await this.chunkList({ const existingRecords = await this.chunkList({
pks: dataWithPks.map((v) => v.pk), pks: dataWithPks.map((v) => v.pk),
@ -5349,20 +5347,18 @@ class BaseModelSqlv2 {
} }
} }
trx = await this.dbDriver.transaction();
const updatedPks = [];
if (toUpdate.length > 0) { if (toUpdate.length > 0) {
const pks = [];
for (const data of toUpdate) { for (const data of toUpdate) {
if (!raw) await this.validate(data, columns); if (!raw) await this.validate(data, columns);
const pkValues = this.extractPksValues(data); const pkValues = this.extractPksValues(data);
pks.push(pkValues); updatedPks.push(pkValues);
const wherePk = await this._wherePk(pkValues, true); const wherePk = await this._wherePk(pkValues, true);
await trx(this.tnPath).update(data).where(wherePk); await trx(this.tnPath).update(data).where(wherePk);
} }
const updatedRecords = await this.chunkList({
pks,
});
updatedDatas.push(...updatedRecords);
} }
if (toInsert.length > 0) { if (toInsert.length > 0) {
@ -5420,12 +5416,16 @@ class BaseModelSqlv2 {
await trx.raw('SET foreign_key_checks = 1;'); await trx.raw('SET foreign_key_checks = 1;');
} }
} }
insertedDatas.push(...responses); insertedDatas.push(...responses);
} }
await trx.commit(); await trx.commit();
const updatedRecords = await this.chunkList({
pks: updatedPks,
});
updatedDatas.push(...updatedRecords);
const insertedDataList = const insertedDataList =
insertedDatas.length > 0 insertedDatas.length > 0
? await this.chunkList({ ? await this.chunkList({
@ -5501,7 +5501,7 @@ class BaseModelSqlv2 {
) { ) {
const { allowSystemColumn } = params; const { allowSystemColumn } = params;
const cols = columns || (await this.model.getColumns(this.context)); const cols = columns || (await this.model.getColumns(this.context));
let insertObj = {}; const insertObj = {};
for (let i = 0; i < cols.length; ++i) { for (let i = 0; i < cols.length; ++i) {
const col = cols[i]; const col = cols[i];

Loading…
Cancel
Save