Skip to content

Commit 60d8e79

Browse files
authored
fix: updateOrInsert signature change in 11.10 (#216)
1 parent fbed84c commit 60d8e79

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Query/Builder.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace Colopl\Spanner\Query;
1919

20+
use Closure;
2021
use Colopl\Spanner\Connection;
2122
use Illuminate\Contracts\Support\Arrayable;
2223
use Illuminate\Database\Query\Builder as BaseBuilder;
@@ -61,13 +62,23 @@ public function update(array $values)
6162
/**
6263
* @inheritDoc
6364
*/
64-
public function updateOrInsert(array $attributes, array $values = [])
65+
public function updateOrInsert(array $attributes, array|callable $values = [])
6566
{
66-
if (! $this->where($attributes)->exists()) {
67+
$exists = $this->where($attributes)->exists();
68+
69+
if ($values instanceof Closure) {
70+
$values = $values($exists);
71+
}
72+
73+
if (! $exists) {
6774
return $this->insert(array_merge($attributes, $values));
6875
}
6976

70-
return (bool) $this->take(1)->update(Arr::except($values, array_keys($attributes)));
77+
if (empty($values)) {
78+
return true;
79+
}
80+
81+
return (bool) $this->limit(1)->update(Arr::except($values, array_keys($attributes)));
7182
}
7283

7384
/**

0 commit comments

Comments
 (0)