Skip to content

Commit 798a98e

Browse files
committed
test: 修复 SAP HANA 和 PostgreSQL 的 SQL 生成问题
- 更新了 SAP HANA 数据库的 MERGE INTO 语句生成逻辑 - 修正了 PostgreSQL 数据库的 INSERT ON CONFLICT 语句中的 WHERE 子句
1 parent ee10f0a commit 798a98e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/query-builder/InsertQueryBuilder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ export class InsertQueryBuilder<
609609
this.expressionMap.onUpdate.overwriteCondition ??= []
610610
const wheres = overwrite.map<WhereClause>((column) => ({
611611
type: "or",
612-
condition: `${this.escape(this.alias)}.${this.escape(
612+
condition: `${this.escape(
613+
this.alias,
614+
)}.${this.escape(
613615
column,
614616
)} IS DISTINCT FROM EXCLUDED.${this.escape(
615617
column,

test/functional/query-builder/insert-merge-into/query-builder-insert-merge-into.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ describe("query builder > insertion > merge into", () => {
168168
`WHEN MATCHED AND post.date > @4 AND post.title != mergeIntoSource.title THEN UPDATE SET post.title = mergeIntoSource.title ` +
169169
`WHEN NOT MATCHED THEN INSERT(id, title, published, date) VALUES (mergeIntoSource.id, mergeIntoSource.title, mergeIntoSource.published, mergeIntoSource.date);`,
170170
)
171+
}
172+
if (connection.options.type === "sap") {
173+
expect(sql).to.equal(
174+
`MERGE INTO post post USING (SELECT ? AS id, ? AS title, ? AS published, ? AS date FROM SYS.DUMMY) mergeIntoSource ON (post.date = mergeIntoSource.date) ` +
175+
`WHEN MATCHED AND post.date > ? AND post.title != mergeIntoSource.title THEN UPDATE SET post.title = mergeIntoSource.title ` +
176+
`WHEN NOT MATCHED THEN INSERT(id, title, published, date) VALUES (mergeIntoSource.id, mergeIntoSource.title, mergeIntoSource.published, mergeIntoSource.date)`,
177+
)
171178
} else {
172179
expect(sql).to.equal(
173180
`MERGE INTO post post USING (SELECT :1 AS id, :2 AS title, :3 AS published, :4 AS date FROM DUAL) mergeIntoSource ON (post.date = mergeIntoSource.date) ` +

test/functional/query-builder/insert-on-conflict/query-builder-insert-on-conflict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ describe("query builder > insert > on conflict", () => {
315315
`INSERT INTO post(id, title, date) ` +
316316
`VALUES ($1, $2, $3) ON CONFLICT ( date ) ` +
317317
`WHERE ( date > 2020-01-01 ) DO UPDATE SET title = EXCLUDED.title ` +
318-
`WHERE (post.title IS DISTINCT FROM EXCLUDED.title)`,
318+
`WHERE post.title IS DISTINCT FROM EXCLUDED.title`,
319319
)
320320
}),
321321
))

0 commit comments

Comments
 (0)