1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Cycle ORM package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Cycle\Database\Driver\SQLite\Query\Traits; |
13
|
|
|
|
14
|
|
|
use Cycle\Database\Driver\SQLite\Injection\CompileJson; |
15
|
|
|
use Cycle\Database\Driver\SQLite\Injection\CompileJsonContainsKey; |
16
|
|
|
use Cycle\Database\Driver\SQLite\Injection\CompileJsonDoesntContainKey; |
17
|
|
|
use Cycle\Database\Driver\SQLite\Injection\CompileJsonLength; |
18
|
|
|
use Cycle\Database\Exception\BuilderException; |
19
|
|
|
use Cycle\Database\Exception\DriverException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @internal |
23
|
|
|
* |
24
|
|
|
* @psalm-internal Cycle\Database\Driver\SQLite |
25
|
|
|
*/ |
26
|
|
|
trait WhereJsonTrait |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param non-empty-string $column |
|
|
|
|
30
|
|
|
* @param non-empty-string $method |
31
|
|
|
* @param array<non-empty-string, mixed> $params |
32
|
|
|
*/ |
33
|
|
|
protected function buildJsonInjection( |
34
|
|
|
string $column, |
35
|
|
|
mixed $value, |
36
|
|
|
string $method, |
37
|
|
|
array $params, |
38
|
|
|
): array { |
39
|
|
|
return match ($method) { |
40
|
|
|
'whereJson', 'orWhereJson' => [new CompileJson($column), $value], |
41
|
|
|
'whereJsonContains', 'orWhereJsonContains', 'whereJsonDoesntContain', |
42
|
|
|
'orWhereJsonDoesntContain' => throw new DriverException( |
43
|
|
|
'This SQLite does not support JSON contains operations.' |
44
|
|
|
), |
45
|
|
|
'whereJsonContainsKey', 'orWhereJsonContainsKey' => [new CompileJsonContainsKey($column)], |
46
|
|
|
'whereJsonDoesntContainKey', 'orWhereJsonDoesntContainKey' => [new CompileJsonDoesntContainKey($column)], |
47
|
|
|
'whereJsonLength', 'orWhereJsonLength' => [new CompileJsonLength($column, $value, $params['operator'])], |
48
|
|
|
default => null, |
49
|
|
|
} ?? throw new BuilderException("This database engine can't handle the `$method` method."); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|