|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns; |
|
6
|
|
|
|
|
7
|
|
|
use ArangoClient\Exceptions\ArangoException; |
|
8
|
|
|
|
|
9
|
|
|
trait HandlesViews |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param array<mixed> $properties |
|
13
|
|
|
* |
|
14
|
|
|
* @throws ArangoException |
|
15
|
|
|
*/ |
|
16
|
65 |
|
public function createView(string $name, array $properties, string $type = 'arangosearch') |
|
17
|
|
|
{ |
|
18
|
65 |
|
$view = $properties; |
|
19
|
65 |
|
$view['name'] = $name; |
|
20
|
65 |
|
$view['type'] = $type; |
|
21
|
|
|
|
|
22
|
65 |
|
$this->schemaManager->createView($view); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @throws ArangoException |
|
27
|
|
|
*/ |
|
28
|
2 |
|
public function getView(string $name): \stdClass |
|
29
|
|
|
{ |
|
30
|
2 |
|
return $this->schemaManager->getView($name); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
59 |
|
public function hasView($view) |
|
34
|
|
|
{ |
|
35
|
59 |
|
return $this->handleExceptionsAsQueryExceptions(function () use ($view) { |
|
|
|
|
|
|
36
|
59 |
|
return $this->schemaManager->hasView($view); |
|
37
|
59 |
|
}); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @throws ArangoException |
|
42
|
|
|
*/ |
|
43
|
8 |
|
public function getViews(): array |
|
44
|
|
|
{ |
|
45
|
8 |
|
return $this->schemaManager->getViews(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @throws ArangoException |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function editView(string $name, array $properties) |
|
52
|
|
|
{ |
|
53
|
2 |
|
$this->schemaManager->updateView($name, $properties); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @throws ArangoException |
|
58
|
|
|
*/ |
|
59
|
2 |
|
public function renameView(string $from, string $to) |
|
60
|
|
|
{ |
|
61
|
2 |
|
$this->schemaManager->renameView($from, $to); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @throws ArangoException |
|
66
|
|
|
*/ |
|
67
|
2 |
|
public function dropView(string $name) |
|
68
|
|
|
{ |
|
69
|
2 |
|
$this->schemaManager->deleteView($name); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @throws ArangoException |
|
74
|
|
|
*/ |
|
75
|
59 |
|
public function dropViewIfExists(string $name): bool |
|
76
|
|
|
{ |
|
77
|
59 |
|
if ($this->hasView($name)) { |
|
78
|
24 |
|
$this->schemaManager->deleteView($name); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
59 |
|
return true; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Drop all views from the schema. |
|
86
|
|
|
* |
|
87
|
|
|
* @throws ArangoException |
|
88
|
|
|
*/ |
|
89
|
35 |
|
public function dropAllViews(): void |
|
90
|
|
|
{ |
|
91
|
35 |
|
$this->schemaManager->deleteAllViews(); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|