diff --git a/src/query-builder/merge-query-builder.ts b/src/query-builder/merge-query-builder.ts index 8bab1b6c6..dfdcddb42 100644 --- a/src/query-builder/merge-query-builder.ts +++ b/src/query-builder/merge-query-builder.ts @@ -22,8 +22,17 @@ import { } from '../parser/join-parser.js' import { parseMergeThen, parseMergeWhen } from '../parser/merge-parser.js' import { ReferenceExpression } from '../parser/reference-parser.js' -import { ReturningAllRow, ReturningRow } from '../parser/returning-parser.js' -import { parseSelectAll, parseSelectArg } from '../parser/select-parser.js' +import { + ReturningAllRow, + ReturningCallbackRow, + ReturningRow, +} from '../parser/returning-parser.js' +import { + parseSelectAll, + parseSelectArg, + SelectCallback, + SelectExpression, +} from '../parser/select-parser.js' import { TableExpression } from '../parser/table-parser.js' import { parseTop } from '../parser/top-parser.js' import { @@ -59,10 +68,13 @@ import { SelectExpressionFromOutputCallback, SelectExpressionFromOutputExpression, } from './output-interface.js' +import { MultiTableReturningInterface } from './returning-interface.js' import { UpdateQueryBuilder } from './update-query-builder.js' export class MergeQueryBuilder - implements OutputInterface + implements + MultiTableReturningInterface, + OutputInterface { readonly #props: MergeQueryBuilderProps @@ -214,6 +226,48 @@ export class MergeQueryBuilder }) } + returning>( + selections: ReadonlyArray, + ): MergeQueryBuilder> + + returning>( + callback: CB, + ): MergeQueryBuilder> + + returning>( + selection: SE, + ): MergeQueryBuilder> + + returning(args: any): any { + return new MergeQueryBuilder({ + ...this.#props, + queryNode: QueryNode.cloneWithReturning( + this.#props.queryNode, + parseSelectArg(args), + ), + }) + } + + returningAll( + tables: ReadonlyArray, + ): MergeQueryBuilder> + + returningAll( + table: T, + ): MergeQueryBuilder> + + returningAll(): MergeQueryBuilder> + + returningAll(table?: any): any { + return new MergeQueryBuilder({ + ...this.#props, + queryNode: QueryNode.cloneWithReturning( + this.#props.queryNode, + parseSelectAll(table), + ), + }) + } + output>( selections: readonly OE[], ): MergeQueryBuilder< @@ -273,7 +327,11 @@ export class WheneableMergeQueryBuilder< ST extends keyof DB, O, > - implements Compilable, OutputInterface, OperationNodeSource + implements + Compilable, + MultiTableReturningInterface, + OutputInterface, + OperationNodeSource { readonly #props: MergeQueryBuilderProps @@ -605,6 +663,58 @@ export class WheneableMergeQueryBuilder< return this.#whenNotMatched([lhs, op, rhs], true, true) } + returning>( + selections: ReadonlyArray, + ): WheneableMergeQueryBuilder> + + returning>( + callback: CB, + ): WheneableMergeQueryBuilder< + DB, + TT, + ST, + ReturningCallbackRow + > + + returning>( + selection: SE, + ): WheneableMergeQueryBuilder> + + returning(args: any): any { + return new WheneableMergeQueryBuilder({ + ...this.#props, + queryNode: QueryNode.cloneWithReturning( + this.#props.queryNode, + parseSelectArg(args), + ), + }) + } + + returningAll( + tables: ReadonlyArray, + ): WheneableMergeQueryBuilder> + + returningAll( + table: T, + ): WheneableMergeQueryBuilder> + + returningAll(): WheneableMergeQueryBuilder< + DB, + TT, + ST, + ReturningAllRow + > + + returningAll(table?: any): any { + return new WheneableMergeQueryBuilder({ + ...this.#props, + queryNode: QueryNode.cloneWithReturning( + this.#props.queryNode, + parseSelectAll(table), + ), + }) + } + output>( selections: readonly OE[], ): WheneableMergeQueryBuilder<