QueryBuilder: Add upsert
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
Is your feature request related to a problem? Please describe.
PostgreSQL and MariaDB/MySQL will log a unique constraint violation in their logs (e.g. duplicate key value violates unique constraint for PostgreSQL). Even if the exception is handled in our application code, the log will still clutter the logs.
We introduced insertIgnoreConflict to suppress the error, but it still requires two SQL statements. Nicer would be to add support for upserts to our query builder.
Doctrine DBAL does not support upserts.
Laravel supports upsert:https://github.com/laravel/framework/pull/34698/files
Upsert is not standardized, and thus the actual query looks different for each vendor:
- MariaDB: https://mariadb.com/kb/en/insert-on-duplicate-key-update/
- PostgreSQL: https://www.postgresql.org/docs/current/sql-insert.html (see "ON CONFLICT")
- SQLite: https://sqlite.org/lang_upsert.html
- Oracle: Try to use merge or fallback to insert + update
Possible use cases for upsert.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the QueryBuilder implementation and its database-driver abstractions. Compare the vendor-specific upsert forms linked in the issue, including the Oracle fallback, and define the supported API and behavior for each vendor; done means upsert support is implemented consistently across the intended drivers and verified by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php, postgresql, sqlite
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100