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\CompileJsonDoesntContain; |
17
|
|
|
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonLength; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @internal |
21
|
|
|
*/ |
22
|
|
|
trait WhereJsonTrait |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param non-empty-string $column |
|
|
|
|
26
|
|
|
* |
27
|
|
|
* @return $this|self |
28
|
|
|
*/ |
29
|
|
|
public function whereJson(string $column, mixed $value): self |
30
|
|
|
{ |
31
|
|
|
$this->registerToken( |
|
|
|
|
32
|
|
|
'AND', |
33
|
|
|
[new CompileJson($column), $value], |
34
|
|
|
$this->whereTokens, |
35
|
|
|
$this->whereWrapper() |
|
|
|
|
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param non-empty-string $column |
|
|
|
|
43
|
|
|
* |
44
|
|
|
* @return $this|self |
45
|
|
|
*/ |
46
|
|
|
public function andWhereJson(string $column, mixed $value): self |
47
|
|
|
{ |
48
|
|
|
return $this->whereJson($column, $value); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param non-empty-string $column |
|
|
|
|
53
|
|
|
* |
54
|
|
|
* @return $this|self |
55
|
|
|
*/ |
56
|
|
|
public function orWhereJson(string $column, mixed $value): self |
57
|
|
|
{ |
58
|
|
|
$this->registerToken( |
59
|
|
|
'OR', |
60
|
|
|
[new CompileJson($column), $value], |
61
|
|
|
$this->whereTokens, |
62
|
|
|
$this->whereWrapper() |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param non-empty-string $column |
|
|
|
|
70
|
|
|
* |
71
|
|
|
* @return $this|self |
72
|
|
|
*/ |
73
|
|
|
public function whereJsonContains(string $column, mixed $value): self |
74
|
|
|
{ |
75
|
|
|
$this->registerToken( |
76
|
|
|
'AND', |
77
|
|
|
[new CompileJsonContains($column, $value)], |
78
|
|
|
$this->whereTokens, |
79
|
|
|
$this->whereWrapper() |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param non-empty-string $column |
|
|
|
|
87
|
|
|
* |
88
|
|
|
* @return $this|self |
89
|
|
|
*/ |
90
|
|
|
public function andWhereJsonContains(string $column, mixed $value): self |
91
|
|
|
{ |
92
|
|
|
return $this->whereJsonContains($column, $value); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param non-empty-string $column |
|
|
|
|
97
|
|
|
* |
98
|
|
|
* @return $this|self |
99
|
|
|
*/ |
100
|
|
|
public function orWhereJsonContains(string $column, mixed $value): self |
101
|
|
|
{ |
102
|
|
|
$this->registerToken( |
103
|
|
|
'OR', |
104
|
|
|
[new CompileJsonContains($column, $value)], |
105
|
|
|
$this->whereTokens, |
106
|
|
|
$this->whereWrapper() |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param non-empty-string $column |
|
|
|
|
114
|
|
|
* |
115
|
|
|
* @return $this|self |
116
|
|
|
*/ |
117
|
|
|
public function whereJsonDoesntContain(string $column, mixed $value): self |
118
|
|
|
{ |
119
|
|
|
$this->registerToken( |
120
|
|
|
'AND', |
121
|
|
|
[new CompileJsonDoesntContain($column, $value)], |
122
|
|
|
$this->whereTokens, |
123
|
|
|
$this->whereWrapper() |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param non-empty-string $column |
|
|
|
|
131
|
|
|
* |
132
|
|
|
* @return $this|self |
133
|
|
|
*/ |
134
|
|
|
public function andWhereJsonDoesntContain(string $column, mixed $value): self |
135
|
|
|
{ |
136
|
|
|
return $this->whereJsonDoesntContain($column, $value); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param non-empty-string $column |
|
|
|
|
141
|
|
|
* |
142
|
|
|
* @return $this|self |
143
|
|
|
*/ |
144
|
|
|
public function orWhereJsonDoesntContain(string $column, mixed $value): self |
145
|
|
|
{ |
146
|
|
|
$this->registerToken( |
147
|
|
|
'OR', |
148
|
|
|
[new CompileJsonDoesntContain($column, $value)], |
149
|
|
|
$this->whereTokens, |
150
|
|
|
$this->whereWrapper() |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param non-empty-string $column |
|
|
|
|
158
|
|
|
* @param 0|positive-int $length |
159
|
|
|
* @param non-empty-string $operator |
160
|
|
|
* |
161
|
|
|
* @return $this|self |
162
|
|
|
*/ |
163
|
|
|
public function whereJsonLength(string $column, int $length, string $operator = '='): self |
164
|
|
|
{ |
165
|
|
|
$this->registerToken( |
166
|
|
|
'AND', |
167
|
|
|
[new CompileJsonLength($column, $length, $operator)], |
168
|
|
|
$this->whereTokens, |
169
|
|
|
$this->whereWrapper() |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param non-empty-string $column |
|
|
|
|
177
|
|
|
* @param 0|positive-int $length |
178
|
|
|
* @param non-empty-string $operator |
179
|
|
|
* |
180
|
|
|
* @return $this|self |
181
|
|
|
*/ |
182
|
|
|
public function andWhereJsonLength(string $column, int $length, string $operator = '='): self |
183
|
|
|
{ |
184
|
|
|
return $this->whereJsonLength($column, $length, $operator); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param non-empty-string $column |
|
|
|
|
189
|
|
|
* @param 0|positive-int $length |
190
|
|
|
* @param non-empty-string $operator |
191
|
|
|
* |
192
|
|
|
* @return $this|self |
193
|
|
|
*/ |
194
|
|
|
public function orWhereJsonLength(string $column, int $length, string $operator = '='): self |
195
|
|
|
{ |
196
|
|
|
$this->registerToken( |
197
|
|
|
'OR', |
198
|
|
|
[new CompileJsonLength($column, $length, $operator)], |
199
|
|
|
$this->whereTokens, |
200
|
|
|
$this->whereWrapper() |
201
|
|
|
); |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|