From ed06f4c1f1056837f03a97a25762742a12620a94 Mon Sep 17 00:00:00 2001 From: Arseny Yankovsky Date: Wed, 30 Mar 2022 17:18:12 +0200 Subject: [PATCH] fix: `.save` repository method not returning generated uuids for aurora-postgres (#8825) * fix: fixed .save repository method not returning generated uuids for aurora driver * fix(aurora-postgres): fixed .save repository method not returning generated uuids for aurora driver --- src/driver/DriverUtils.ts | 4 ++++ src/query-builder/InsertQueryBuilder.ts | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/driver/DriverUtils.ts b/src/driver/DriverUtils.ts index 31c8bd47c3..d60b982053 100644 --- a/src/driver/DriverUtils.ts +++ b/src/driver/DriverUtils.ts @@ -32,6 +32,10 @@ export class DriverUtils { return ["mysql", "mariadb"].includes(driver.options.type) } + static isPostgresFamily(driver: Driver): boolean { + return ["postgres", "aurora-postgres"].includes(driver.options.type) + } + /** * Normalizes and builds a new driver options. * Extracts settings from connection url and sets to a new options object. diff --git a/src/query-builder/InsertQueryBuilder.ts b/src/query-builder/InsertQueryBuilder.ts index 1aa5545de9..044105b32d 100644 --- a/src/query-builder/InsertQueryBuilder.ts +++ b/src/query-builder/InsertQueryBuilder.ts @@ -412,7 +412,7 @@ export class InsertQueryBuilder extends QueryBuilder { if ( this.alias !== this.getMainTableName() && - this.connection.driver.options.type === "postgres" + DriverUtils.isPostgresFamily(this.connection.driver) ) { query += ` AS "${this.alias}"` } @@ -507,7 +507,7 @@ export class InsertQueryBuilder extends QueryBuilder { if ( Array.isArray(overwrite) && skipUpdateIfNoValuesChanged && - this.connection.driver.options.type === "postgres" + DriverUtils.isPostgresFamily(this.connection.driver) ) { query += ` WHERE (` query += overwrite @@ -560,7 +560,7 @@ export class InsertQueryBuilder extends QueryBuilder { // add RETURNING expression if ( returningExpression && - (this.connection.driver.options.type === "postgres" || + (DriverUtils.isPostgresFamily(this.connection.driver) || this.connection.driver.options.type === "oracle" || this.connection.driver.options.type === "cockroachdb" || DriverUtils.isMySQLFamily(this.connection.driver)) @@ -829,8 +829,9 @@ export class InsertQueryBuilder extends QueryBuilder { expression += `${geomFromText}(${paramName})` } } else if ( - this.connection.driver.options.type === - "postgres" && + DriverUtils.isPostgresFamily( + this.connection.driver, + ) && this.connection.driver.spatialTypes.indexOf( column.type, ) !== -1