Skip to content

Commit d9734b5

Browse files
committed
Added compatibility with binary UUIDs.
1 parent d880c4e commit d9734b5

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [0.7.3] - 2019-12-22
88
### Added
99
- documentation to explain that database transactions are currently not supported.
10+
- compatibility with binary UUIDs. Thanks @padre!
1011

1112
### Changed
1213
- detection if cache is enabled in the `$model->all()` method. Thanks @titrxw!

src/CacheKey.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php namespace GeneaLabs\LaravelModelCaching;
22

3+
use Exception;
34
use GeneaLabs\LaravelModelCaching\Traits\CachePrefixing;
45
use Illuminate\Support\Arr;
56
use Illuminate\Support\Collection;
67
use Illuminate\Support\Str;
8+
use Ramsey\Uuid\Uuid;
79

810
class CacheKey
911
{
@@ -229,6 +231,18 @@ protected function getInAndNotInClauses(array $where) : string
229231
$subquery = $this->getValuesFromWhere($where);
230232
$values = collect($this->query->bindings["where"][$this->currentBinding] ?? []);
231233
$this->currentBinding += count($where["values"]);
234+
235+
if (! is_numeric($subquery) && ! is_numeric(str_replace("_", "", $subquery))) {
236+
try {
237+
$subquery = Uuid::fromBytes($subquery);
238+
$values = $this->recursiveImplode([$subquery], "_");
239+
240+
return "-{$where["column"]}_{$type}{$values}";
241+
} catch (Exception $exception) {
242+
// do nothing
243+
}
244+
}
245+
232246
$subquery = preg_replace('/\?(?=(?:[^"]*"[^"]*")*[^"]*\Z)/m', "_??_", $subquery);
233247
$subquery = collect(vsprintf(str_replace("_??_", "%s", $subquery), $values->toArray()));
234248
$values = $this->recursiveImplode($subquery->toArray(), "_");

tests/database/baseline.sqlite

-28 KB
Binary file not shown.

tests/database/testing.sqlite

-28 KB
Binary file not shown.

0 commit comments

Comments
 (0)