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

Support update table1, table2, ... query support. Closes #192 #1079

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

koskimas
Copy link
Member

@koskimas koskimas commented Jul 14, 2024

Adds support for queries like this:

update
  person,
  pet
set
  person.first_name = ?,
  pet.name = ?
where
  person.id = pet.owner_id
  and person.name = ?

This kind of queries are supported by (at least) MySQL. As discussed in #192 we can't really make the join methods work with both MySQL and PostgreSQL since postgres joins add tables to the TB generic and MySQL would need to add to both UT and TB generics.

The set({ first_name: 'foo' }) version of the set method doesn't support table qualified references. The users need to use the set('table.column', value) version.

Copy link

vercel bot commented Jul 14, 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 Jul 14, 2024 11:52am

@koskimas koskimas force-pushed the add-update-multiple-tables-support branch 2 times, most recently from f6d7cc1 to 30f1f72 Compare July 14, 2024 09:31
@koskimas koskimas force-pushed the add-update-multiple-tables-support branch from 30f1f72 to 8674b06 Compare July 14, 2024 09:33
@igalklebanov igalklebanov added enhancement New feature or request mysql Related to MySQL api Related to library's API labels Jul 14, 2024
@koskimas koskimas force-pushed the add-update-multiple-tables-support branch from 8674b06 to a7f99fa Compare July 14, 2024 09:35
@koskimas koskimas changed the base branch from master to v0.28 July 14, 2024 09:41
@koskimas koskimas force-pushed the add-update-multiple-tables-support branch from a7f99fa to 05bd329 Compare July 14, 2024 09:41
@koskimas
Copy link
Member Author

koskimas commented Jul 14, 2024

I'm rebasing this to 0.28, but I think that branch is broken. The QueryNode.cloneWithEndModifier method is missing.

@igalklebanov
Copy link
Member

I'm rebasing this to 0.28, but I think that branch is broken. The QueryNode.cloneWithEndModifier method is missing.

Yeah, it was 3 commits behind or something. I forgot to rebase it.

@koskimas
Copy link
Member Author

I'm rebasing this to 0.28, but I think that branch is broken. The QueryNode.cloneWithEndModifier method is missing.

Yeah, it was 3 commits behind or something. I forgot to rebase it.

Actually, I just accidentally picked up the modifyEnd method when rebasing 😬

Copy link
Member

@igalklebanov igalklebanov left a comment

Choose a reason for hiding this comment

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

Hey 👋

Overall LGTM as always! 🚀

I left some nitpicky comments..

I wonder if we could make set's object variant work for this scenario. Was it a type-complexity decision or something else?

@koskimas
Copy link
Member Author

koskimas commented Jul 14, 2024

I wonder if we could make set's object variant work for this scenario. Was it a type-complexity decision or something else?

I'm afraid that auto-completion would lead postgres etc. users to use the table qualified names even though they only work on mysql. The object version already works for columns that are unambiguous. For example this works:

db.updateTable(['person', 'pet'])
  .set({ first_name: 'foo', name: 'bar' })

first_name is a person column and name is a pet column.

@koskimas koskimas force-pushed the add-update-multiple-tables-support branch from bbc168e to 932699c Compare July 14, 2024 11:52
@koskimas koskimas merged commit 9ae6948 into v0.28 Jul 14, 2024
12 checks passed
@koskimas koskimas deleted the add-update-multiple-tables-support branch July 17, 2024 07:11
igalklebanov pushed a commit to igalklebanov/kysely that referenced this pull request Oct 4, 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 mysql Related to MySQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants