|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\AQL; |
|
6
|
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\InsertClause; |
|
8
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\LetClause; |
|
9
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\RemoveClause; |
|
10
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\ReplaceClause; |
|
11
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\UpdateClause; |
|
12
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\UpsertClause; |
|
13
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
|
14
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Trait hasStatementClauses |
|
18
|
|
|
* API calls to add data modification commands to the builder. |
|
19
|
|
|
*/ |
|
20
|
|
|
trait HasStatementClauses |
|
21
|
|
|
{ |
|
22
|
|
|
abstract public function addCommand($command); |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Assign a value to a variable. |
|
26
|
|
|
* |
|
27
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/operations-let.html |
|
28
|
|
|
* |
|
29
|
|
|
* @param array<mixed>|string|QueryBuilder|Expression $expression |
|
30
|
|
|
*/ |
|
31
|
4 |
|
public function let( |
|
32
|
|
|
string $variableName, |
|
33
|
|
|
mixed $expression |
|
34
|
|
|
): self { |
|
35
|
4 |
|
$this->addCommand(new LetClause($variableName, $expression)); |
|
36
|
|
|
|
|
37
|
4 |
|
return $this; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Insert a document in a collection. |
|
42
|
|
|
* |
|
43
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/operations-insert.html |
|
44
|
|
|
* |
|
45
|
|
|
* @param array<mixed>|object|string $document |
|
46
|
|
|
*/ |
|
47
|
2 |
|
public function insert( |
|
48
|
|
|
array|object|string $document, |
|
49
|
|
|
string|QueryBuilder|Expression $collection |
|
50
|
|
|
): self { |
|
51
|
2 |
|
$this->addCommand(new InsertClause($document, $collection)); |
|
52
|
|
|
|
|
53
|
2 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Update a document in a collection with the supplied data. |
|
58
|
|
|
* |
|
59
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/operations-update.html |
|
60
|
|
|
* |
|
61
|
|
|
* @param array<mixed>|string|object $document |
|
62
|
|
|
* @param array<mixed>|string|object $with |
|
63
|
|
|
*/ |
|
64
|
2 |
|
public function update( |
|
65
|
|
|
array|string|object $document, |
|
66
|
|
|
array|string|object $with, |
|
67
|
|
|
string|QueryBuilder|Expression $collection |
|
68
|
|
|
): self { |
|
69
|
2 |
|
$this->addCommand(new UpdateClause($document, $with, $collection)); |
|
70
|
|
|
|
|
71
|
2 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Replace a document in a collection with the supplied data. |
|
76
|
|
|
* |
|
77
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/operations-replace.html |
|
78
|
|
|
* |
|
79
|
|
|
* @param array<mixed>|object|string $document |
|
80
|
|
|
* @param array<mixed>|object|string $with |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function replace( |
|
83
|
|
|
array|object|string $document, |
|
84
|
|
|
array|object|string $with, |
|
85
|
|
|
string|QueryBuilder|Expression $collection |
|
86
|
|
|
): self { |
|
87
|
1 |
|
$this->addCommand(new ReplaceClause($document, $with, $collection)); |
|
88
|
|
|
|
|
89
|
1 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Update, replace or insert documents in a collection with the supplied data. |
|
94
|
|
|
* |
|
95
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/operations-upsert.html |
|
96
|
|
|
* |
|
97
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
|
98
|
|
|
* |
|
99
|
|
|
* @param array<mixed>|object|string $search |
|
100
|
|
|
* @param array<mixed>|object|string $insert |
|
101
|
|
|
* @param array<mixed>|object|string $update |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function upsert( |
|
104
|
|
|
array|object|string $search, |
|
105
|
|
|
array|object|string $insert, |
|
106
|
|
|
array|object|string $update, |
|
107
|
|
|
string|QueryBuilder|Expression $collection, |
|
108
|
|
|
bool $replace = false |
|
109
|
|
|
): self { |
|
110
|
1 |
|
$this->addCommand(new UpsertClause($search, $insert, $update, $collection, $replace)); |
|
111
|
|
|
|
|
112
|
1 |
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Remove a document from a collection. |
|
117
|
|
|
* |
|
118
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/operations-remove.html |
|
119
|
|
|
* @param array<mixed>|string|object $document |
|
120
|
|
|
*/ |
|
121
|
2 |
|
public function remove( |
|
122
|
|
|
array|object|string $document, |
|
123
|
|
|
string|QueryBuilder|Expression $collection |
|
124
|
|
|
): self { |
|
125
|
2 |
|
$this->addCommand(new RemoveClause($document, $collection)); |
|
126
|
|
|
|
|
127
|
2 |
|
return $this; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|