|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns; |
|
6
|
|
|
|
|
7
|
|
|
use ArangoClient\Exceptions\ArangoException; |
|
8
|
|
|
|
|
9
|
|
|
trait HandlesGraphs |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param array<mixed> $properties |
|
13
|
|
|
* @throws ArangoException |
|
14
|
|
|
* |
|
15
|
|
|
* @SuppressWarnings("PHPMD.BooleanArgumentFlag") |
|
16
|
|
|
*/ |
|
17
|
8 |
|
public function createGraph(string $name, array $properties = [], bool $waitForSync = false) |
|
18
|
|
|
{ |
|
19
|
8 |
|
$this->schemaManager->createGraph($name, $properties, $waitForSync); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
2 |
|
public function hasGraph(string $name): bool |
|
23
|
|
|
{ |
|
24
|
2 |
|
return $this->handleExceptionsAsQueryExceptions(function () use ($name) { |
|
|
|
|
|
|
25
|
2 |
|
return $this->schemaManager->hasGraph($name); |
|
26
|
2 |
|
}); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param string $name |
|
31
|
|
|
* @return mixed[] |
|
32
|
|
|
* @throws ArangoException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getGraph(string $name): array |
|
35
|
|
|
{ |
|
36
|
|
|
return (array) $this->schemaManager->getGraph($name); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return mixed[] |
|
41
|
|
|
* @throws ArangoException |
|
42
|
|
|
*/ |
|
43
|
8 |
|
public function getGraphs(): array |
|
44
|
|
|
{ |
|
45
|
8 |
|
return $this->mapResultsToArray( |
|
|
|
|
|
|
46
|
8 |
|
$this->schemaManager->getGraphs(), |
|
47
|
8 |
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @throws ArangoException |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function dropGraph(string $name) |
|
54
|
|
|
{ |
|
55
|
1 |
|
$this->schemaManager->deleteGraph($name); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @throws ArangoException |
|
60
|
|
|
*/ |
|
61
|
2 |
|
public function dropGraphIfExists(string $name): bool |
|
62
|
|
|
{ |
|
63
|
2 |
|
if ($this->hasGraph($name)) { |
|
64
|
1 |
|
$this->schemaManager->deleteGraph($name); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
35 |
|
public function dropAllGraphs(): void |
|
71
|
|
|
{ |
|
72
|
35 |
|
$this->schemaManager->deleteAllGraphs(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|