|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\AQL; |
|
6
|
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
|
8
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression; |
|
9
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Array AQL functions. |
|
13
|
|
|
* |
|
14
|
|
|
* @see https://www.arangodb.com/docs/stable/aql/functions-array.html |
|
15
|
|
|
*/ |
|
16
|
|
|
trait HasArrayFunctions |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Add all elements of an array to another array. |
|
20
|
|
|
* |
|
21
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#append |
|
22
|
|
|
* |
|
23
|
|
|
* @param array<mixed>|object $array |
|
24
|
|
|
* @param mixed $values |
|
25
|
|
|
* @param bool|null $unique |
|
26
|
|
|
* @return FunctionExpression |
|
27
|
|
|
*/ |
|
28
|
2 |
|
public function append(mixed $array, mixed $values, bool $unique = null): FunctionExpression |
|
29
|
|
|
{ |
|
30
|
2 |
|
$arguments = [ |
|
31
|
2 |
|
'array' => $array, |
|
32
|
2 |
|
'values' => $values, |
|
33
|
|
|
]; |
|
34
|
2 |
|
if (isset($unique)) { |
|
35
|
1 |
|
$arguments['unique'] = $unique; |
|
36
|
|
|
} |
|
37
|
2 |
|
return new FunctionExpression('APPEND', $arguments); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* This is an alias for LENGTH(). |
|
42
|
|
|
* |
|
43
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#length |
|
44
|
|
|
* |
|
45
|
|
|
* @param mixed $value |
|
46
|
|
|
* @return FunctionExpression |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function count($value): FunctionExpression |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->length($value); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the number of unique elements. |
|
55
|
|
|
* |
|
56
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#count_distinct |
|
57
|
|
|
* |
|
58
|
|
|
* @param mixed $value |
|
59
|
|
|
* |
|
60
|
|
|
* @return FunctionExpression |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function countDistinct($value): FunctionExpression |
|
63
|
|
|
{ |
|
64
|
1 |
|
return new FunctionExpression('COUNT_DISTINCT', [$value]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get the first element of an array. |
|
69
|
|
|
* |
|
70
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#first |
|
71
|
|
|
* |
|
72
|
|
|
* @param mixed $value |
|
73
|
|
|
* |
|
74
|
|
|
* @return FunctionExpression |
|
75
|
|
|
*/ |
|
76
|
2 |
|
public function first($value): FunctionExpression |
|
77
|
|
|
{ |
|
78
|
2 |
|
return new FunctionExpression('FIRST', [$value]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Turn an array of arrays into a flat array. |
|
83
|
|
|
* |
|
84
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#flatten |
|
85
|
|
|
* |
|
86
|
|
|
* @param array<mixed>|object $array |
|
87
|
|
|
* @param int|object $depth |
|
88
|
|
|
* @return FunctionExpression |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function flatten(mixed $array, mixed $depth = 1): FunctionExpression |
|
91
|
|
|
{ |
|
92
|
1 |
|
$arguments = [ |
|
93
|
1 |
|
'array' => $array, |
|
94
|
1 |
|
'depth' => $depth, |
|
95
|
|
|
]; |
|
96
|
|
|
|
|
97
|
1 |
|
return new FunctionExpression('FLATTEN', $arguments); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return the intersection of all arrays specified. |
|
102
|
|
|
* |
|
103
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#intersection |
|
104
|
|
|
* |
|
105
|
|
|
* @param array<mixed> ...$arrays |
|
106
|
|
|
* @return FunctionExpression |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function intersection(array ...$arrays): FunctionExpression |
|
109
|
|
|
{ |
|
110
|
1 |
|
return new FunctionExpression('INTERSECTION', $arrays); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get the last element of an array. |
|
115
|
|
|
* |
|
116
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#last |
|
117
|
|
|
* |
|
118
|
|
|
* @param mixed $value |
|
119
|
|
|
* |
|
120
|
|
|
* @return FunctionExpression |
|
121
|
|
|
*/ |
|
122
|
1 |
|
public function last($value): FunctionExpression |
|
123
|
|
|
{ |
|
124
|
1 |
|
return new FunctionExpression('LAST', [$value]); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#length |
|
129
|
|
|
* |
|
130
|
|
|
* @param mixed $value |
|
131
|
|
|
* |
|
132
|
|
|
* @return FunctionExpression |
|
133
|
|
|
*/ |
|
134
|
2 |
|
public function length(mixed $value): FunctionExpression |
|
135
|
|
|
{ |
|
136
|
2 |
|
return new FunctionExpression('LENGTH', [$value]); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Remove the first element of an array. |
|
141
|
|
|
* |
|
142
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#shift |
|
143
|
|
|
* |
|
144
|
|
|
* @param array<mixed>|object $array |
|
145
|
|
|
* @return FunctionExpression |
|
146
|
|
|
*/ |
|
147
|
1 |
|
public function shift(mixed $array): FunctionExpression |
|
148
|
|
|
{ |
|
149
|
1 |
|
return new FunctionExpression('SHIFT', [$array]); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Return the union of all arrays specified. |
|
154
|
|
|
* |
|
155
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#union |
|
156
|
|
|
* |
|
157
|
|
|
* @param array<mixed>|Expression|QueryBuilder $arrays |
|
158
|
|
|
* @return FunctionExpression |
|
159
|
|
|
*/ |
|
160
|
1 |
|
public function union( |
|
161
|
|
|
array|Expression|QueryBuilder ...$arrays |
|
162
|
|
|
): FunctionExpression { |
|
163
|
1 |
|
return new FunctionExpression('UNION', [$arrays]); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Return the union of distinct values of all arrays specified. |
|
168
|
|
|
* |
|
169
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#union_distinct |
|
170
|
|
|
* |
|
171
|
|
|
* @param array<mixed>|Expression|QueryBuilder $arrays |
|
172
|
|
|
* @return FunctionExpression |
|
173
|
|
|
*/ |
|
174
|
1 |
|
public function unionDistinct( |
|
175
|
|
|
array|Expression|QueryBuilder ...$arrays |
|
176
|
|
|
): FunctionExpression { |
|
177
|
1 |
|
return new FunctionExpression('UNION_DISTINCT', [$arrays]); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Return all unique elements in an Array. |
|
182
|
|
|
* |
|
183
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-array.html#unique |
|
184
|
|
|
* |
|
185
|
|
|
* @param array<mixed>|object $array |
|
186
|
|
|
* @return FunctionExpression |
|
187
|
|
|
*/ |
|
188
|
1 |
|
public function unique(mixed $array): FunctionExpression |
|
189
|
|
|
{ |
|
190
|
1 |
|
return new FunctionExpression('UNIQUE', [$array]); |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|