1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\Clauses; |
6
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
8
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
9
|
|
|
|
10
|
|
|
class UpdateClause extends Clause |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array<mixed>|object|string $document |
14
|
|
|
*/ |
15
|
|
|
protected array|object|string $document; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array<mixed>|object|string $with |
19
|
|
|
*/ |
20
|
|
|
protected array|object|string $with; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string|QueryBuilder|Expression $collection |
24
|
|
|
*/ |
25
|
|
|
protected string|QueryBuilder|Expression $collection; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param array<mixed>|object|string $document |
29
|
|
|
* @param array<mixed>|object|string $with |
30
|
|
|
* @param string|QueryBuilder|Expression $collection |
31
|
|
|
*/ |
32
|
2 |
|
public function __construct( |
33
|
|
|
array|object|string $document, |
34
|
|
|
array|object|string $with, |
35
|
|
|
string|QueryBuilder|Expression $collection |
36
|
|
|
) { |
37
|
2 |
|
parent::__construct(); |
38
|
|
|
|
39
|
2 |
|
$this->document = $document; |
40
|
2 |
|
$this->with = $with; |
41
|
2 |
|
$this->collection = $collection; |
42
|
|
|
} |
43
|
|
|
|
44
|
2 |
|
public function compile(QueryBuilder $queryBuilder): string |
45
|
|
|
{ |
46
|
2 |
|
$this->document = $queryBuilder->normalizeArgument( |
47
|
2 |
|
$this->document, |
48
|
2 |
|
['RegisteredVariable', 'Key', 'Object', 'Bind'] |
49
|
|
|
); |
50
|
2 |
|
$this->with = $queryBuilder->normalizeArgument($this->with, ['Object', 'Bind']); |
51
|
2 |
|
$this->collection = $queryBuilder->normalizeArgument($this->collection, ['Collection', 'Bind']); |
52
|
2 |
|
$queryBuilder->registerCollections($this->collection->compile($queryBuilder)); |
53
|
|
|
|
54
|
2 |
|
return "UPDATE {$this->document->compile($queryBuilder)} " . |
55
|
2 |
|
"WITH {$this->with->compile($queryBuilder)} " . |
56
|
2 |
|
"IN {$this->collection->compile($queryBuilder)}"; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|