Skip to content

Commit

Permalink
fix merge queries not being transformed. (kysely-org#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov authored and thecodrr committed Sep 3, 2024
1 parent 12f0405 commit 6524651
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/query-builder/merge-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ export class WheneableMergeQueryBuilder<

compile(): CompiledQuery<never> {
return this.#props.executor.compileQuery(
this.#props.queryNode,
this.toOperationNode(),
this.#props.queryId,
)
}
Expand Down
38 changes: 38 additions & 0 deletions test/node/src/camel-case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
expect,
createTableWithId,
DIALECTS,
NOT_SUPPORTED,
} from './test-setup.js'

for (const dialect of DIALECTS) {
Expand Down Expand Up @@ -277,6 +278,43 @@ for (const dialect of DIALECTS) {
disable_emails: true,
})
})

if (dialect === 'postgres' || dialect === 'mssql') {
it('should convert merge queries', async () => {
const query = camelDb
.mergeInto('camelPerson')
.using(
'camelPerson as anotherCamelPerson',
'camelPerson.firstName',
'anotherCamelPerson.firstName',
)
.whenMatched()
.thenUpdateSet((eb) => ({
firstName: sql<string>`concat(${eb.ref('anotherCamelPerson.firstName')}, ${sql.lit('2')})`,
}))

testSql(query, dialect, {
postgres: {
sql: [
`merge into "camel_person"`,
`using "camel_person" as "another_camel_person" on "camel_person"."first_name" = "another_camel_person"."first_name"`,
`when matched then update set "first_name" = concat("another_camel_person"."first_name", '2')`,
],
parameters: [],
},
mysql: NOT_SUPPORTED,
mssql: {
sql: [
`merge into "camel_person"`,
`using "camel_person" as "another_camel_person" on "camel_person"."first_name" = "another_camel_person"."first_name"`,
`when matched then update set "first_name" = concat("another_camel_person"."first_name", '2');`,
],
parameters: [],
},
sqlite: NOT_SUPPORTED,
})
})
}
})
}

Expand Down

0 comments on commit 6524651

Please sign in to comment.