Skip to content

Commit

Permalink
fix signature
Browse files Browse the repository at this point in the history
  • Loading branch information
taka-oyama committed Jun 5, 2024
1 parent 9ae85ed commit 4135a0b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Colopl\Spanner\Query;

use Closure;
use Colopl\Spanner\Connection;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Query\Builder as BaseBuilder;
Expand Down Expand Up @@ -58,6 +59,28 @@ public function update(array $values)
return parent::update($values);
}

/**
* @inheritDoc
*/
public function updateOrInsert(array $attributes, array|callable $values = [])
{
$exists = $this->where($attributes)->exists();

if ($values instanceof Closure) {
$values = $values($exists);
}

if (! $exists) {
return $this->insert(array_merge($attributes, $values));
}

if (empty($values)) {
return true;
}

return (bool) $this->limit(1)->update(Arr::except($values, array_keys($attributes)));
}

/**
* @inheritDoc
*/
Expand Down

0 comments on commit 4135a0b

Please sign in to comment.