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