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\DriverException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
* |
23
|
|
|
* @psalm-internal Cycle\Database\Driver\SQLite |
24
|
|
|
*/ |
25
|
|
|
trait WhereJsonTrait |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param non-empty-string $column |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function whereJson(string $column, mixed $value): static |
31
|
|
|
{ |
32
|
|
|
$this->registerToken( |
|
|
|
|
33
|
|
|
'AND', |
34
|
|
|
[new CompileJson($column), $value], |
35
|
|
|
$this->whereTokens, |
36
|
|
|
$this->whereWrapper() |
|
|
|
|
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param non-empty-string $column |
|
|
|
|
44
|
|
|
*/ |
45
|
|
|
public function andWhereJson(string $column, mixed $value): static |
46
|
|
|
{ |
47
|
|
|
return $this->whereJson($column, $value); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param non-empty-string $column |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
public function orWhereJson(string $column, mixed $value): static |
54
|
|
|
{ |
55
|
|
|
$this->registerToken( |
56
|
|
|
'OR', |
57
|
|
|
[new CompileJson($column), $value], |
58
|
|
|
$this->whereTokens, |
59
|
|
|
$this->whereWrapper() |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param non-empty-string $column |
|
|
|
|
67
|
|
|
* @param bool $encode Encode the value into JSON. |
68
|
|
|
* @param bool $validate Checking the value that it is valid JSON. |
69
|
|
|
*/ |
70
|
|
|
public function whereJsonContains(string $column, mixed $value, bool $encode = true, bool $validate = true): static |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
throw new DriverException('This database engine does not support JSON contains operations.'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param non-empty-string $column |
|
|
|
|
77
|
|
|
* @param bool $encode Encode the value into JSON. |
78
|
|
|
* @param bool $validate Checking the value that it is valid JSON. |
79
|
|
|
*/ |
80
|
|
|
public function andWhereJsonContains( |
81
|
|
|
string $column, |
|
|
|
|
82
|
|
|
mixed $value, |
|
|
|
|
83
|
|
|
bool $encode = true, |
|
|
|
|
84
|
|
|
bool $validate = true |
|
|
|
|
85
|
|
|
): static { |
86
|
|
|
throw new DriverException('This database engine does not support JSON contains operations.'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param non-empty-string $column |
|
|
|
|
91
|
|
|
* @param bool $encode Encode the value into JSON. |
92
|
|
|
* @param bool $validate Checking the value that it is valid JSON. |
93
|
|
|
*/ |
94
|
|
|
public function orWhereJsonContains( |
95
|
|
|
string $column, |
|
|
|
|
96
|
|
|
mixed $value, |
|
|
|
|
97
|
|
|
bool $encode = true, |
|
|
|
|
98
|
|
|
bool $validate = true |
|
|
|
|
99
|
|
|
): static { |
100
|
|
|
throw new DriverException('This database engine does not support JSON contains operations.'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param non-empty-string $column |
|
|
|
|
105
|
|
|
* @param bool $encode Encode the value into JSON. |
106
|
|
|
* @param bool $validate Checking the value that it is valid JSON. |
107
|
|
|
*/ |
108
|
|
|
public function whereJsonDoesntContain( |
109
|
|
|
string $column, |
|
|
|
|
110
|
|
|
mixed $value, |
|
|
|
|
111
|
|
|
bool $encode = true, |
|
|
|
|
112
|
|
|
bool $validate = true |
|
|
|
|
113
|
|
|
): static { |
114
|
|
|
throw new DriverException('This database engine does not support JSON contains operations.'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param non-empty-string $column |
|
|
|
|
119
|
|
|
* @param bool $encode Encode the value into JSON. |
120
|
|
|
* @param bool $validate Checking the value that it is valid JSON. |
121
|
|
|
*/ |
122
|
|
|
public function andWhereJsonDoesntContain( |
123
|
|
|
string $column, |
|
|
|
|
124
|
|
|
mixed $value, |
|
|
|
|
125
|
|
|
bool $encode = true, |
|
|
|
|
126
|
|
|
bool $validate = true |
|
|
|
|
127
|
|
|
): static { |
128
|
|
|
throw new DriverException('This database engine does not support JSON contains operations.'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param non-empty-string $column |
|
|
|
|
133
|
|
|
* @param bool $encode Encode the value into JSON. |
134
|
|
|
* @param bool $validate Checking the value that it is valid JSON. |
135
|
|
|
*/ |
136
|
|
|
public function orWhereJsonDoesntContain( |
137
|
|
|
string $column, |
|
|
|
|
138
|
|
|
mixed $value, |
|
|
|
|
139
|
|
|
bool $encode = true, |
|
|
|
|
140
|
|
|
bool $validate = true |
|
|
|
|
141
|
|
|
): static { |
142
|
|
|
throw new DriverException('This database engine does not support JSON contains operations.'); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param non-empty-string $column |
|
|
|
|
147
|
|
|
*/ |
148
|
|
|
public function whereJsonContainsKey(string $column): static |
149
|
|
|
{ |
150
|
|
|
$this->registerToken( |
151
|
|
|
'AND', |
152
|
|
|
[new CompileJsonContainsKey($column)], |
153
|
|
|
$this->whereTokens, |
154
|
|
|
$this->whereWrapper() |
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param non-empty-string $column |
|
|
|
|
162
|
|
|
*/ |
163
|
|
|
public function andWhereJsonContainsKey(string $column): static |
164
|
|
|
{ |
165
|
|
|
return $this->whereJsonContainsKey($column); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param non-empty-string $column |
|
|
|
|
170
|
|
|
*/ |
171
|
|
|
public function orWhereJsonContainsKey(string $column): static |
172
|
|
|
{ |
173
|
|
|
$this->registerToken( |
174
|
|
|
'OR', |
175
|
|
|
[new CompileJsonContainsKey($column)], |
176
|
|
|
$this->whereTokens, |
177
|
|
|
$this->whereWrapper() |
178
|
|
|
); |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param non-empty-string $column |
|
|
|
|
185
|
|
|
*/ |
186
|
|
|
public function whereJsonDoesntContainKey(string $column): static |
187
|
|
|
{ |
188
|
|
|
$this->registerToken( |
189
|
|
|
'AND', |
190
|
|
|
[new CompileJsonDoesntContainKey($column)], |
191
|
|
|
$this->whereTokens, |
192
|
|
|
$this->whereWrapper() |
193
|
|
|
); |
194
|
|
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param non-empty-string $column |
|
|
|
|
200
|
|
|
*/ |
201
|
|
|
public function andWhereJsonDoesntContainKey(string $column): static |
202
|
|
|
{ |
203
|
|
|
return $this->whereJsonDoesntContainKey($column); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param non-empty-string $column |
|
|
|
|
208
|
|
|
*/ |
209
|
|
|
public function orWhereJsonDoesntContainKey(string $column): static |
210
|
|
|
{ |
211
|
|
|
$this->registerToken( |
212
|
|
|
'OR', |
213
|
|
|
[new CompileJsonDoesntContainKey($column)], |
214
|
|
|
$this->whereTokens, |
215
|
|
|
$this->whereWrapper() |
216
|
|
|
); |
217
|
|
|
|
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param non-empty-string $column |
|
|
|
|
223
|
|
|
* @param int<0, max> $length |
224
|
|
|
* @param non-empty-string $operator |
225
|
|
|
*/ |
226
|
|
|
public function whereJsonLength(string $column, int $length, string $operator = '='): static |
227
|
|
|
{ |
228
|
|
|
$this->registerToken( |
229
|
|
|
'AND', |
230
|
|
|
[new CompileJsonLength($column, $length, $operator)], |
231
|
|
|
$this->whereTokens, |
232
|
|
|
$this->whereWrapper() |
233
|
|
|
); |
234
|
|
|
|
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param non-empty-string $column |
|
|
|
|
240
|
|
|
* @param int<0, max> $length |
241
|
|
|
* @param non-empty-string $operator |
242
|
|
|
*/ |
243
|
|
|
public function andWhereJsonLength(string $column, int $length, string $operator = '='): static |
244
|
|
|
{ |
245
|
|
|
return $this->whereJsonLength($column, $length, $operator); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param non-empty-string $column |
|
|
|
|
250
|
|
|
* @param int<0, max> $length |
251
|
|
|
* @param non-empty-string $operator |
252
|
|
|
*/ |
253
|
|
|
public function orWhereJsonLength(string $column, int $length, string $operator = '='): static |
254
|
|
|
{ |
255
|
|
|
$this->registerToken( |
256
|
|
|
'OR', |
257
|
|
|
[new CompileJsonLength($column, $length, $operator)], |
258
|
|
|
$this->whereTokens, |
259
|
|
|
$this->whereWrapper() |
260
|
|
|
); |
261
|
|
|
|
262
|
|
|
return $this; |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|