Skip to content

Commit

Permalink
whereIn query when the updated value is always the same
Browse files Browse the repository at this point in the history
Signed-off-by: William <[email protected]>
  • Loading branch information
wfeller committed Mar 30, 2022
1 parent 691d70c commit 2e5dff8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Updater/GenericUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ final class GenericUpdater implements Updater
{
public function performUpdate(Settings $settings, string $column, array $values, array $ids) : void
{
if (1 === count($values)) {
$settings->dbConnection
->table($settings->table)
->whereIn($settings->keyName, $ids)
->update([
$column => $values[0]
]);

return;
}

$settings->dbConnection->update(
$this->sql($settings, $column, count($values)),
array_merge(Alternate::arrays($ids, $values), $ids)
Expand Down
11 changes: 11 additions & 0 deletions src/Updater/PostgresUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public static function addCastMapping(string $type, string $castUsing) : void

public function performUpdate(Settings $settings, string $column, array $values, array $ids) : void
{
if (1 === count($values)) {
$settings->dbConnection
->table($settings->table)
->whereIn($settings->keyName, $ids)
->update([
$column => $values[0]
]);

return;
}

$this->keyCast = in_array($settings->keyType, ['int', 'integer']) ? '::integer' : '::text';

$settings->dbConnection->update(
Expand Down

0 comments on commit 2e5dff8

Please sign in to comment.