nextcloud / nextcloud/server

QueryBuilder: Add upsert

Open
#48,595 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage enhancement feature: database
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:

Possible use cases for upsert.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.