Skip to content

Commit

Permalink
add MERGE query support. (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov authored Jan 8, 2024
1 parent 24ef0f5 commit 9deb62a
Show file tree
Hide file tree
Showing 31 changed files with 2,664 additions and 255 deletions.
224 changes: 2 additions & 222 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/dialect/mssql/mssql-query-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AddColumnNode } from '../../operation-node/add-column-node.js'
import { AlterTableColumnAlterationNode } from '../../operation-node/alter-table-node.js'
import { DropColumnNode } from '../../operation-node/drop-column-node.js'
import { MergeQueryNode } from '../../operation-node/merge-query-node.js'
import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js'

export class MssqlQueryCompiler extends DefaultQueryCompiler {
Expand Down Expand Up @@ -73,6 +74,11 @@ export class MssqlQueryCompiler extends DefaultQueryCompiler {
this.visitNode(node.column)
}

protected override visitMergeQuery(node: MergeQueryNode): void {
super.visitMergeQuery(node)
this.append(';')
}

protected override announcesNewColumnDataType(): boolean {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion src/dialect/postgres/postgres-dialect-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type PostgresCursorConstructor = new <T>(
) => PostgresCursor<T>

export interface PostgresQueryResult<R> {
command: 'UPDATE' | 'DELETE' | 'INSERT' | 'SELECT'
command: 'UPDATE' | 'DELETE' | 'INSERT' | 'SELECT' | 'MERGE'
rowCount: number
rows: R[]
}
Expand Down
3 changes: 2 additions & 1 deletion src/dialect/postgres/postgres-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class PostgresConnection implements DatabaseConnection {
if (
result.command === 'INSERT' ||
result.command === 'UPDATE' ||
result.command === 'DELETE'
result.command === 'DELETE' ||
result.command === 'MERGE'
) {
const numAffectedRows = BigInt(result.rowCount)

Expand Down
2 changes: 1 addition & 1 deletion src/driver/database-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface QueryResult<O> {
readonly numUpdatedOrDeletedRows?: bigint

/**
* This is defined for insert, update and delete queries and contains
* This is defined for insert, update, delete and merge queries and contains
* the number of rows the query inserted/updated/deleted.
*/
readonly numAffectedRows?: bigint
Expand Down
Loading

1 comment on commit 9deb62a

@vercel
Copy link

@vercel vercel bot commented on 9deb62a Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kysely – ./

kysely-kysely-team.vercel.app
kysely-git-master-kysely-team.vercel.app
www.kysely.dev
kysely.dev

Please sign in to comment.