1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\Query; |
5
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\Message\MessageInterface; |
7
|
|
|
use TBolier\RethinkQL\Query\Exception\QueryException; |
8
|
|
|
use TBolier\RethinkQL\Query\Logic\AndLogic; |
9
|
|
|
use TBolier\RethinkQL\Query\Logic\EqualLogic; |
10
|
|
|
use TBolier\RethinkQL\Query\Logic\FuncLogic; |
11
|
|
|
use TBolier\RethinkQL\Query\Logic\GetFieldLogic; |
12
|
|
|
use TBolier\RethinkQL\Query\Logic\GreaterThanLogic; |
13
|
|
|
use TBolier\RethinkQL\Query\Logic\GreaterThanOrEqualToLogic; |
14
|
|
|
use TBolier\RethinkQL\Query\Logic\LowerThanLogic; |
15
|
|
|
use TBolier\RethinkQL\Query\Logic\LowerThanOrEqualToLogic; |
16
|
|
|
use TBolier\RethinkQL\Query\Logic\NotEqualLogic; |
17
|
|
|
use TBolier\RethinkQL\Query\Logic\NotLogic; |
18
|
|
|
use TBolier\RethinkQL\Query\Logic\OrLogic; |
19
|
|
|
use TBolier\RethinkQL\RethinkInterface; |
20
|
|
|
|
21
|
|
|
class Row extends AbstractQuery implements RowInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var QueryInterface |
25
|
|
|
*/ |
26
|
|
|
private $function; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var QueryInterface |
30
|
|
|
*/ |
31
|
|
|
private $query; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $value; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param RethinkInterface $rethink |
40
|
|
|
* @param string $value |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
RethinkInterface $rethink, |
44
|
|
|
string $value |
45
|
|
|
) { |
46
|
|
|
parent::__construct($rethink); |
47
|
|
|
|
48
|
|
|
$this->value = $value; |
49
|
|
|
$this->rethink = $rethink; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
* @throws QueryException |
55
|
|
|
*/ |
56
|
|
|
public function eq($value): RowInterface |
57
|
|
|
{ |
58
|
|
|
if (!\is_scalar($value)) { |
59
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->function = new EqualLogic( |
63
|
|
|
$this->rethink, |
64
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
65
|
|
|
$value |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->query = new FuncLogic( |
69
|
|
|
$this->rethink, |
70
|
|
|
$this->function |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
* @throws QueryException |
79
|
|
|
*/ |
80
|
|
|
public function ne($value): RowInterface |
81
|
|
|
{ |
82
|
|
|
if (!\is_scalar($value)) { |
83
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->function = new NotEqualLogic( |
87
|
|
|
$this->rethink, |
88
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
89
|
|
|
$value |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$this->query = new FuncLogic( |
93
|
|
|
$this->rethink, |
94
|
|
|
$this->function |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
* @throws QueryException |
103
|
|
|
*/ |
104
|
|
|
public function lt($value): RowInterface |
105
|
|
|
{ |
106
|
|
|
if (!\is_scalar($value)) { |
107
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$this->function = new LowerThanLogic( |
111
|
|
|
$this->rethink, |
112
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
113
|
|
|
$value |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
$this->query = new FuncLogic( |
117
|
|
|
$this->rethink, |
118
|
|
|
$this->function |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @inheritdoc |
126
|
|
|
* @throws QueryException |
127
|
|
|
*/ |
128
|
|
|
public function le($value): RowInterface |
129
|
|
|
{ |
130
|
|
|
if (!\is_scalar($value)) { |
131
|
|
|
throw new QueryException('Only scalar types are supported for lower than or equal manipulations.'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$this->function = new LowerThanOrEqualToLogic( |
135
|
|
|
$this->rethink, |
136
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
137
|
|
|
$value |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
$this->query = new FuncLogic( |
141
|
|
|
$this->rethink, |
142
|
|
|
$this->function |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @inheritdoc |
150
|
|
|
* @throws QueryException |
151
|
|
|
*/ |
152
|
|
|
public function gt($value): RowInterface |
153
|
|
|
{ |
154
|
|
|
if (!\is_scalar($value)) { |
155
|
|
|
throw new QueryException('Only scalar types are supported for greater than manipulations.'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$this->function = new GreaterThanLogic( |
159
|
|
|
$this->rethink, |
160
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
161
|
|
|
$value |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
$this->query = new FuncLogic( |
165
|
|
|
$this->rethink, |
166
|
|
|
$this->function |
167
|
|
|
); |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @inheritdoc |
174
|
|
|
* @throws QueryException |
175
|
|
|
*/ |
176
|
|
|
public function ge($value): RowInterface |
177
|
|
|
{ |
178
|
|
|
if (!\is_scalar($value)) { |
179
|
|
|
throw new QueryException('Only scalar types are supported for greater than or equal manipulations.'); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$this->function = new GreaterThanOrEqualToLogic( |
183
|
|
|
$this->rethink, |
184
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
185
|
|
|
$value |
186
|
|
|
); |
187
|
|
|
|
188
|
|
|
$this->query = new FuncLogic( |
189
|
|
|
$this->rethink, |
190
|
|
|
$this->function |
191
|
|
|
); |
192
|
|
|
|
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param RowInterface $row |
198
|
|
|
* @return RowInterface |
199
|
|
|
*/ |
200
|
|
|
public function and(RowInterface $row): RowInterface |
201
|
|
|
{ |
202
|
|
|
$this->function = new AndLogic( |
203
|
|
|
$this->rethink, |
204
|
|
|
$this->function, |
205
|
|
|
$row->getFunction() |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$this->query = new FuncLogic( |
209
|
|
|
$this->rethink, |
210
|
|
|
$this->function |
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param RowInterface $row |
218
|
|
|
* @return RowInterface |
219
|
|
|
*/ |
220
|
|
|
public function or(RowInterface $row): RowInterface |
221
|
|
|
{ |
222
|
|
|
$this->function = new OrLogic( |
223
|
|
|
$this->rethink, |
224
|
|
|
$this->function, |
225
|
|
|
$row->getFunction() |
226
|
|
|
); |
227
|
|
|
|
228
|
|
|
$this->query = new FuncLogic( |
229
|
|
|
$this->rethink, |
230
|
|
|
$this->function |
231
|
|
|
); |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @param RowInterface $row |
238
|
|
|
* @return RowInterface |
239
|
|
|
*/ |
240
|
|
|
public function not(): RowInterface |
241
|
|
|
{ |
242
|
|
|
$this->function = new NotLogic( |
243
|
|
|
$this->rethink, |
244
|
|
|
$this->function |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
$this->query = new FuncLogic( |
248
|
|
|
$this->rethink, |
249
|
|
|
$this->function |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
return $this; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @inheritdoc |
257
|
|
|
*/ |
258
|
|
|
public function toArray(): array |
259
|
|
|
{ |
260
|
|
|
return $this->query->toArray(); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return QueryInterface |
265
|
|
|
*/ |
266
|
|
|
public function getFunction(): QueryInterface |
267
|
|
|
{ |
268
|
|
|
return $this->function; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|