feat: Added support for upserting data#231
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #231 +/- ##
============================================
+ Coverage 95.43% 95.62% +0.19%
- Complexity 1942 2003 +61
============================================
Files 133 136 +3
Lines 5414 5652 +238
============================================
+ Hits 5167 5405 +238
Misses 247 247 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
# Conflicts: # tests/Database/Functional/Driver/Common/Schema/TableTest.php
|
@cycle/core-contributors I've just recently merged 2.x updates, ensuring everything in this PR is up-to-date. I'd really like to see this make it's way into the codebase, as upsert functionality is something I've become accustomed to across other ORM's and languages, and something I feel others would appreciate. Let me know if there's anything further needed from me, to get this over the line. |
|
@copilot resolve the merge conflicts in this pull request |
# Conflicts: # src/Driver/Postgres/PostgresDriver.php # src/Driver/SQLite/SQLiteDriver.php Co-authored-by: roxblnfk <4152481+roxblnfk@users.noreply.github.com>
Resolved and pushed in commit 22dfb17. I merged the latest Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Hi. It's time! :D After reviewing the PR with ClaudeCode in detail, I plan to implement upsert support with a different architecture in a separate PR. The rationale and the alternative API are summarised at the end of this review. The alternative we plan to implementRather than introducing a new query type, the upsert will live as an optional state on $db->insert('users')
->values($row)
->onConflict(
OnConflict::target('email')->doUpdate(['name'])->where(...)
)
->returning('id')
->run();
// short form for the common case
$db->insert('users')
->values($row)
->onConflict('email') // accepted as shorthand: DO UPDATE on all columns
->run();
// no-op variant
$db->insert('users')
->values($row)
->onConflict(OnConflict::target('email')->doNothing())
->run();Key differences from this PR's design:
A separate feature request issue will describe this in detail. What do you think? |
This pull request adds support for performing
upsertqueries. Ticket #50 is what sparked interest for this feature.🔍 What was changed
🤔 Why?
📝 Checklist
📃 Documentation
Note that specifying conflict index column names is redundant and not required for
MySQL.PHP
MySQL
Postgres / SQLite
MSSQL