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\LowerThanLogic; |
14
|
|
|
use TBolier\RethinkQL\Query\Logic\NotEqualLogic; |
15
|
|
|
use TBolier\RethinkQL\Query\Logic\NotLogic; |
16
|
|
|
use TBolier\RethinkQL\Query\Logic\OrLogic; |
17
|
|
|
use TBolier\RethinkQL\RethinkInterface; |
18
|
|
|
|
19
|
|
|
class Row extends AbstractQuery implements RowInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var QueryInterface |
23
|
|
|
*/ |
24
|
|
|
private $function; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var QueryInterface |
28
|
|
|
*/ |
29
|
|
|
private $query; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $value; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param RethinkInterface $rethink |
38
|
|
|
* @param string $value |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
RethinkInterface $rethink, |
42
|
|
|
string $value |
43
|
|
|
) { |
44
|
|
|
parent::__construct($rethink); |
45
|
|
|
|
46
|
|
|
$this->value = $value; |
47
|
|
|
$this->rethink = $rethink; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
* @throws QueryException |
53
|
|
|
*/ |
54
|
|
|
public function eq($value): RowInterface |
55
|
|
|
{ |
56
|
|
|
if (!\is_scalar($value)) { |
57
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->function = new EqualLogic( |
61
|
|
|
$this->rethink, |
62
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
63
|
|
|
$value |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->query = new FuncLogic( |
67
|
|
|
$this->rethink, |
68
|
|
|
$this->function |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @inheritdoc |
76
|
|
|
* @throws QueryException |
77
|
|
|
*/ |
78
|
|
|
public function ne($value): RowInterface |
79
|
|
|
{ |
80
|
|
|
if (!\is_scalar($value)) { |
81
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->function = new NotEqualLogic( |
85
|
|
|
$this->rethink, |
86
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
87
|
|
|
$value |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$this->query = new FuncLogic( |
91
|
|
|
$this->rethink, |
92
|
|
|
$this->function |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @inheritdoc |
100
|
|
|
* @throws QueryException |
101
|
|
|
*/ |
102
|
|
|
public function lt($value): RowInterface |
103
|
|
|
{ |
104
|
|
|
if (!\is_scalar($value)) { |
105
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->function = new LowerThanLogic( |
109
|
|
|
$this->rethink, |
110
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
111
|
|
|
$value |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$this->query = new FuncLogic( |
115
|
|
|
$this->rethink, |
116
|
|
|
$this->function |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @inheritdoc |
124
|
|
|
* @throws QueryException |
125
|
|
|
*/ |
126
|
|
|
public function gt($value): RowInterface |
127
|
|
|
{ |
128
|
|
|
if (!\is_scalar($value)) { |
129
|
|
|
throw new QueryException('Only scalar types are supported for greater than manipulations.'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$this->function = new GreaterThanLogic( |
133
|
|
|
$this->rethink, |
134
|
|
|
new GetFieldLogic($this->rethink, $this->value), |
135
|
|
|
$value |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$this->query = new FuncLogic( |
139
|
|
|
$this->rethink, |
140
|
|
|
$this->function |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param RowInterface $row |
148
|
|
|
* @return RowInterface |
149
|
|
|
*/ |
150
|
|
|
public function and(RowInterface $row): RowInterface |
151
|
|
|
{ |
152
|
|
|
$this->function = new AndLogic( |
153
|
|
|
$this->rethink, |
154
|
|
|
$this->function, |
155
|
|
|
$row->getFunction() |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
$this->query = new FuncLogic( |
159
|
|
|
$this->rethink, |
160
|
|
|
$this->function |
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param RowInterface $row |
168
|
|
|
* @return RowInterface |
169
|
|
|
*/ |
170
|
|
|
public function or(RowInterface $row): RowInterface |
171
|
|
|
{ |
172
|
|
|
$this->function = new OrLogic( |
173
|
|
|
$this->rethink, |
174
|
|
|
$this->function, |
175
|
|
|
$row->getFunction() |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
$this->query = new FuncLogic( |
179
|
|
|
$this->rethink, |
180
|
|
|
$this->function |
181
|
|
|
); |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param RowInterface $row |
188
|
|
|
* @return RowInterface |
189
|
|
|
*/ |
190
|
|
|
public function not(): RowInterface |
191
|
|
|
{ |
192
|
|
|
$this->function = new NotLogic( |
193
|
|
|
$this->rethink, |
194
|
|
|
$this->function |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
$this->query = new FuncLogic( |
198
|
|
|
$this->rethink, |
199
|
|
|
$this->function |
200
|
|
|
); |
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @inheritdoc |
207
|
|
|
*/ |
208
|
|
|
public function toArray(): array |
209
|
|
|
{ |
210
|
|
|
return $this->query->toArray(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @return QueryInterface |
215
|
|
|
*/ |
216
|
|
|
public function getFunction(): QueryInterface |
217
|
|
|
{ |
218
|
|
|
return $this->function; |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|