Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add returning support in MERGE queries. #1171

Merged
merged 2 commits into from
Dec 1, 2024

Conversation

igalklebanov
Copy link
Member

@igalklebanov igalklebanov commented Oct 7, 2024

Hey 👋

closes #1169.

As of PostgreSQL 17, MERGE queries now have returning clause support.

  • add returning/returningAll to MERGE.
  • add MultiTableReturningInterface, enforce it across DeleteQueryBuilder, UpdateQueryBuilder and MERGE builders. Why? the existing ReturningInterface doesn't have the returningAll(tables) methods, and INSERT queries are the only ones that don't support returning table.*.
  • add a way to return merge_action() in a type-safe and aliasable way - a PostgreSQL helper function was found to be the lightest solution. Expanding the ExpressionBuilder locally (only for returning) with eb.mergeAction() was also tested, but was adding way more changes. I think that with documentation we could nullify the worse discoverability.
  • unit tests.
  • typings tests.

@igalklebanov igalklebanov added api Related to library's API enhancement New feature or request postgres Related to PostgreSQL labels Oct 7, 2024
Copy link

vercel bot commented Oct 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 1, 2024 2:20pm

@igalklebanov igalklebanov marked this pull request as ready for review October 20, 2024 13:42
@igalklebanov igalklebanov requested a review from koskimas October 20, 2024 14:07
@igalklebanov igalklebanov force-pushed the v0.28 branch 2 times, most recently from b2b78db to ae5cb1e Compare October 24, 2024 12:39
Copy link

pkg-pr-new bot commented Nov 24, 2024

Open in Stackblitzkysely_koa_example

npm i https://pkg.pr.new/kysely-org/kysely@1171

commit: c0dc22f

add returning compilation.

add MultiTableReturningInterface.

add returning/returningAll @ MergeQueryBuilder.

add returning @ transformer.

add returning handling @ execute.

fix returningAll not allowing source table in single variant.

remove multi table variant returningAll.

add unit tests.

allow overriding which expression builder is created in select parsers.

support merge_action()

unit tests.

Discard changes to src/parser/expression-parser.ts
Discard changes to src/parser/select-parser.ts
extract `mergeAction` to helper instead.

..

typings tests.

fix returningAll() typeings test case.

Discard changes to src/parser/merge-parser.ts
@igalklebanov igalklebanov merged commit 09d7ab0 into kysely-org:v0.28 Dec 1, 2024
24 checks passed
@igalklebanov igalklebanov deleted the pg-merge-returning branch December 1, 2024 14:26
igalklebanov added a commit that referenced this pull request Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request postgres Related to PostgreSQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant