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

SQLite's OR CONFLICT clause for inserts #976

Merged
merged 16 commits into from
Jan 6, 2025

Conversation

vincentiusvin
Copy link

@vincentiusvin vincentiusvin commented May 1, 2024

Hello, I saw the good first issue tag and was interested in giving this a shot.

I implemented the orAbort, orFail, orIgnore, etc methods as discussed in #916, alongside making the SQLite override for ignore().
#510 might be of interest too, since this effectively does what was asked there.

Adding support for update or X should be trivial, but I hope that you won't mind if I keep this PR's scope small.

Still got a few design related questions that you can find downstairs, so I'm drafting this. Ready for review.

Closes #916

Functionality not done, only fix type errors
Figured out this is more WYSIWYG than:
- Having no 'or' as the default for a method called 'orX'
- Appending the 'or' as an override in sqlite-query-compiler
Copy link

vercel bot commented May 1, 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 Jan 6, 2025 2:03am

src/operation-node/insert-query-node.ts Outdated Show resolved Hide resolved
src/operation-node/or-conflict-node.ts Outdated Show resolved Hide resolved
src/dialect/mysql/mysql-query-compiler.ts Outdated Show resolved Hide resolved
test/node/src/insert.test.ts Show resolved Hide resolved
@vincentiusvin vincentiusvin changed the title SQLite's OR CONFLICT clause SQLite's OR CONFLICT clause for inserts May 1, 2024
@igalklebanov igalklebanov added enhancement New feature or request sqlite Related to sqlite api Related to library's API labels May 1, 2024
@igalklebanov
Copy link
Member

Adding support for update or X should be trivial, but I hope that you won't mind if I keep this PR's scope small.

Good idea. Let's get insert or X out the door first.

Rename orConflict to orAction
Made the action a string instead of a set of specific strings
@vincentiusvin vincentiusvin marked this pull request as ready for review May 4, 2024 04:09
@igalklebanov igalklebanov changed the base branch from master to v0.28 January 5, 2025 22:58
Co-authored-by: vincentiusvin <54709710+vincentiusvin@users.noreply.github.com>
Co-authored-by: vincentiusvin <54709710+vincentiusvin@users.noreply.github.com>
Copy link

pkg-pr-new bot commented Jan 6, 2025

Open in Stackblitzkysely_koa_example

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

commit: 4a4e76c

Co-authored-by: vincentiusvin <54709710+vincentiusvin@users.noreply.github.com>
@igalklebanov igalklebanov added the mysql Related to MySQL label Jan 6, 2025
@igalklebanov igalklebanov merged commit 1f28e50 into kysely-org:v0.28 Jan 6, 2025
24 checks passed
@igalklebanov
Copy link
Member

igalklebanov commented Jan 6, 2025

Hey 👋

Pushed this through the finish line.

Deprecated InsertQueryNode.ignore in favor of OrActionNode.
DefaultQueryCompiler would still handle ignore property, but will warn of the deprecation.
DefaultQueryCompiler handles OrActionNode the MySQL way - since it is the more popular database - aligned with normally choosing PostgreSQL as the default handling.
SqliteQueryCompiler handles OrActionNode the SQLite way with "or " before the action value.
InsertQueryBuilder.orIgnore is safe for accidental usage by MySQL users, the same way InsertQueryBuilder.ignore is safe for accidental usage by SQLite users.
replaceInto tests are opened for SQLite as well. The support is also reflected in the JSDocs now.

igalklebanov added a commit that referenced this pull request Jan 9, 2025
Co-authored-by: vincentiusvin <54709710+vincentiusvin@users.noreply.github.com>
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
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 breaking change Includes breaking changes enhancement New feature or request mysql Related to MySQL sqlite Related to sqlite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SQLite Dialect] Properly translate .ignore()
2 participants