Skip to content

Commit

Permalink
fix merge queries not being transformed. (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov authored Apr 21, 2024
1 parent 97c5d31 commit fb70aee
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 fb70aee

Please sign in to comment.