Skip to content

Commit 4ffd750

Browse files
Feat/add delete all views (#39)
* Added newline * Added deleteAllViews
1 parent ad5bc11 commit 4ffd750

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

docs/schema-collections.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Delete a collection
8181
```
8282
$arangoClient->schema()->deleteCollection('users');
8383
```
84+
8485
### deleteAllCollections(): bool
8586
This method deletes all non-system collections available on the current database.
8687

docs/schema-views.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ $arangoClient->schema()->updateView('pages', [
6464
$arangoClient->schema()->deleteView('testViewBasics');
6565
```
6666

67+
### deleteAllViews(): bool
68+
This method deletes all views available on the current database.
69+
70+
```
71+
$arangoClient->schema()->deleteAllViews();
72+
```
73+

src/Schema/ManagesViews.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public function deleteView(string $name): bool
4747
return (bool) $this->arangoClient->request('delete', $uri);
4848
}
4949

50+
/**
51+
* @throws ArangoException
52+
*/
53+
public function deleteAllViews(): bool
54+
{
55+
$views = $this->getViews();
56+
57+
foreach ($views as $view) {
58+
$this->deleteView($view->name);
59+
}
60+
61+
return true;
62+
}
63+
5064
/**
5165
* @see https://www.arangodb.com/docs/stable/http/views-arangosearch.html#list-all-views
5266
*

tests/SchemaManagerViewsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,25 @@
8989
$deleted = $this->schemaManager->deleteView($view['name']);
9090
expect($deleted)->toBeTrue();
9191
});
92+
93+
test('deleteAllViews', function () {
94+
$view1 = [
95+
'name' => 'view1',
96+
];
97+
$view2 = [
98+
'name' => 'view2',
99+
];
100+
$this->schemaManager->createView($view1);
101+
$this->schemaManager->createView($view2);
102+
103+
104+
$createdViews = $this->schemaManager->getViews();
105+
106+
$result = $this->schemaManager->deleteAllViews();
107+
108+
$finalViews = $this->schemaManager->getViews();
109+
110+
expect($result)->toBeTrue();
111+
expect(count($createdViews))->toBe(3);
112+
expect(count($finalViews))->toBe(0);
113+
});

0 commit comments

Comments
 (0)