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\SQLServer\Query\Traits; |
13
|
|
|
|
14
|
|
|
use Cycle\Database\Driver\SQLServer\Injection\CompileJson; |
15
|
|
|
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonContains; |
16
|
|
|
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonContainsKey; |
17
|
|
|
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonDoesntContain; |
18
|
|
|
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonDoesntContainKey; |
19
|
|
|
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonLength; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @internal |
23
|
|
|
* |
24
|
|
|
* @psalm-internal Cycle\Database\Driver\SQLServer |
25
|
|
|
*/ |
26
|
|
|
trait WhereJsonTrait |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param non-empty-string $column |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
public function whereJson(string $column, mixed $value): static |
32
|
|
|
{ |
33
|
|
|
$this->registerToken( |
|
|
|
|
34
|
|
|
'AND', |
35
|
|
|
[new CompileJson($column), $value], |
36
|
|
|
$this->whereTokens, |
37
|
|
|
$this->whereWrapper() |
|
|
|
|
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param non-empty-string $column |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function orWhereJson(string $column, mixed $value): static |
47
|
|
|
{ |
48
|
|
|
$this->registerToken( |
49
|
|
|
'OR', |
50
|
|
|
[new CompileJson($column), $value], |
51
|
|
|
$this->whereTokens, |
52
|
|
|
$this->whereWrapper() |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param non-empty-string $column |
|
|
|
|
60
|
|
|
* @param bool $encode Encode the value into JSON. It is not used in this driver. |
61
|
|
|
* @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver. |
62
|
|
|
*/ |
63
|
|
|
public function whereJsonContains(string $column, mixed $value, bool $encode = true, bool $validate = true): static |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$this->registerToken( |
66
|
|
|
'AND', |
67
|
|
|
[new CompileJsonContains($column, $value)], |
68
|
|
|
$this->whereTokens, |
69
|
|
|
$this->whereWrapper() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param non-empty-string $column |
|
|
|
|
77
|
|
|
* @param bool $encode Encode the value into JSON. It is not used in this driver. |
78
|
|
|
* @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver. |
79
|
|
|
*/ |
80
|
|
|
public function orWhereJsonContains( |
81
|
|
|
string $column, |
82
|
|
|
mixed $value, |
83
|
|
|
bool $encode = true, |
|
|
|
|
84
|
|
|
bool $validate = true |
|
|
|
|
85
|
|
|
): static { |
86
|
|
|
$this->registerToken( |
87
|
|
|
'OR', |
88
|
|
|
[new CompileJsonContains($column, $value)], |
89
|
|
|
$this->whereTokens, |
90
|
|
|
$this->whereWrapper() |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param non-empty-string $column |
|
|
|
|
98
|
|
|
* @param bool $encode Encode the value into JSON. It is not used in this driver. |
99
|
|
|
* @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver. |
100
|
|
|
*/ |
101
|
|
|
public function whereJsonDoesntContain( |
102
|
|
|
string $column, |
103
|
|
|
mixed $value, |
104
|
|
|
bool $encode = true, |
|
|
|
|
105
|
|
|
bool $validate = true |
|
|
|
|
106
|
|
|
): static { |
107
|
|
|
$this->registerToken( |
108
|
|
|
'AND', |
109
|
|
|
[new CompileJsonDoesntContain($column, $value)], |
110
|
|
|
$this->whereTokens, |
111
|
|
|
$this->whereWrapper() |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param non-empty-string $column |
|
|
|
|
119
|
|
|
* @param bool $encode Encode the value into JSON. It is not used in this driver. |
120
|
|
|
* @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver. |
121
|
|
|
*/ |
122
|
|
|
public function orWhereJsonDoesntContain( |
123
|
|
|
string $column, |
124
|
|
|
mixed $value, |
125
|
|
|
bool $encode = true, |
|
|
|
|
126
|
|
|
bool $validate = true |
|
|
|
|
127
|
|
|
): static { |
128
|
|
|
$this->registerToken( |
129
|
|
|
'OR', |
130
|
|
|
[new CompileJsonDoesntContain($column, $value)], |
131
|
|
|
$this->whereTokens, |
132
|
|
|
$this->whereWrapper() |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param non-empty-string $column |
|
|
|
|
140
|
|
|
*/ |
141
|
|
|
public function whereJsonContainsKey(string $column): static |
142
|
|
|
{ |
143
|
|
|
$this->registerToken( |
144
|
|
|
'AND', |
145
|
|
|
[new CompileJsonContainsKey($column)], |
146
|
|
|
$this->whereTokens, |
147
|
|
|
$this->whereWrapper() |
148
|
|
|
); |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param non-empty-string $column |
|
|
|
|
155
|
|
|
*/ |
156
|
|
|
public function orWhereJsonContainsKey(string $column): static |
157
|
|
|
{ |
158
|
|
|
$this->registerToken( |
159
|
|
|
'OR', |
160
|
|
|
[new CompileJsonContainsKey($column)], |
161
|
|
|
$this->whereTokens, |
162
|
|
|
$this->whereWrapper() |
163
|
|
|
); |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param non-empty-string $column |
|
|
|
|
170
|
|
|
*/ |
171
|
|
|
public function whereJsonDoesntContainKey(string $column): static |
172
|
|
|
{ |
173
|
|
|
$this->registerToken( |
174
|
|
|
'AND', |
175
|
|
|
[new CompileJsonDoesntContainKey($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 orWhereJsonDoesntContainKey(string $column): static |
187
|
|
|
{ |
188
|
|
|
$this->registerToken( |
189
|
|
|
'OR', |
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
|
|
|
* @param int<0, max> $length |
201
|
|
|
* @param non-empty-string $operator |
202
|
|
|
*/ |
203
|
|
|
public function whereJsonLength(string $column, int $length, string $operator = '='): static |
204
|
|
|
{ |
205
|
|
|
$this->registerToken( |
206
|
|
|
'AND', |
207
|
|
|
[new CompileJsonLength($column, $length, $operator)], |
208
|
|
|
$this->whereTokens, |
209
|
|
|
$this->whereWrapper() |
210
|
|
|
); |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param non-empty-string $column |
|
|
|
|
217
|
|
|
* @param int<0, max> $length |
218
|
|
|
* @param non-empty-string $operator |
219
|
|
|
*/ |
220
|
|
|
public function orWhereJsonLength(string $column, int $length, string $operator = '='): static |
221
|
|
|
{ |
222
|
|
|
$this->registerToken( |
223
|
|
|
'OR', |
224
|
|
|
[new CompileJsonLength($column, $length, $operator)], |
225
|
|
|
$this->whereTokens, |
226
|
|
|
$this->whereWrapper() |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|