From a6eb67b4bef698fd5d0e7a89d383ce441daa8fbf Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 24 Mar 2023 14:03:23 +0800 Subject: [PATCH] refactor(nocodb): bulkUpdateAll logic --- .../db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index ac9de54b4d..5ee052ab85 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -2003,7 +2003,7 @@ class BaseModelSqlv2 { data, { cookie }: { cookie?: any } = {} ) { - let queryResponse; + let res = []; try { const updateData = await this.model.mapAliasToColumn(data); await this.validate(updateData); @@ -2035,13 +2035,19 @@ class BaseModelSqlv2 { ); qb.update(updateData); - queryResponse = (await qb) as any; + + if (this.isPg || this.isMssql) { + qb.returning( + `${this.model.primaryKey.column_name} as ${this.model.primaryKey.title}` + ); + } + + res = (await qb) as any; } - const count = queryResponse ?? 0; - await this.afterBulkUpdate(queryResponse, this.dbDriver, cookie); + await this.afterBulkUpdate(res, this.dbDriver, cookie); - return count; + return res.length; } catch (e) { throw e; }