-
-
Notifications
You must be signed in to change notification settings - Fork 29
Feature/upsert #224
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
Feature/upsert #224
Conversation
One thing I'm uncertain about or dislike at the moment, is the need to specify conflicting index column names for non MySQL drivers. Having said that, most database layers operate in this way, making the user specify conflicting columns. While likely not an appropriate location for such logic, perhaps something like below could work. E.g. gather info from the schema to determine unique indexes and their columns. class UpsertQuery extends ActiveQuery
{
public function getTokens(): array
{
$conflicts = $this->conflicts;
if ($conflicts === [] && $this->driver) {
$schema = $this->driver->getSchemaHandler()->getSchema($this->table);
foreach ($schema->getIndexes() as $index) {
if ($index->isUnique()) {
$conflicts = $conflicts + $index->getColumns();
}
}
$conflicts = array_unique($conflicts);
}
return [
'table' => $this->table,
'columns' => $this->columns,
'values' => $this->values,
'conflicts' => $conflicts,
];
}
} |
@roxblnfk is there anything needed from me to get past that labeler error? Warning: The action requires write permission to add labels to pull requests. For more information please refer to the action documentation: https://github.com/actions/labeler#permissions |
No, don't worry about it. |
# Conflicts: # src/Driver/CompilerInterface.php
Latest changes have been merged, I've bumped public const SUBQUERY = 9;
public const UPSERT_QUERY = 10; |
I haven't had time to look at this PR yet, but it seems you've done a great job. Why did you decide to close it? |
I deleted the forked repositories forgetting this PR was still open, I’ll sort it out first thing in the morning |
This pull request adds support for performing
upsert
queries. 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
MyQL
Postgres / SQLite
MSSQL