Skip to content

Commit daff69c

Browse files
Added createEdgeCollection (#6)
* Added createEdgeCollection method. * Fix styling * Added createEdgeCollection docs. Co-authored-by: LaravelFreelancerNL <LaravelFreelancerNL@users.noreply.github.com>
1 parent f025e79 commit daff69c

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

docs/schema-collections.md

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ Create a collection
5252
$arangoClient->schema()->createCollection('users');
5353
```
5454

55+
### createEdgeCollection(string $name, array $config = [], $waitForSyncReplication = null, $enforceReplicationFactor = null): stdClass
56+
Create an Edge collection
57+
```
58+
$arangoClient->schema()->createEdgeCollection('relationships');
59+
```
60+
5561
### updateCollection(string $name, array $config = []): stdClass
5662
Update a collection
5763
```

src/Schema/ManagesCollections.php

+20
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ public function createCollection(
165165
return $this->arangoClient->request('post', '/_api/collection', $options);
166166
}
167167

168+
/**
169+
* @param string $name
170+
* @param array<mixed> $config
171+
* @param int|bool|null $waitForSyncReplication
172+
* @param int|bool|null $enforceReplicationFactor
173+
* @return stdClass
174+
*
175+
* @throws ArangoException
176+
*/
177+
public function createEdgeCollection(
178+
string $name,
179+
array $config = [],
180+
$waitForSyncReplication = null,
181+
$enforceReplicationFactor = null
182+
): stdClass {
183+
$config['type'] = 3;
184+
185+
return $this->createCollection($name, $config, $waitForSyncReplication, $enforceReplicationFactor);
186+
}
187+
168188
/**
169189
* @param string $name
170190
* @param array<mixed> $config

tests/SchemaManagerCollectionsTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,20 @@ public function testCreateCollectionWithOptions()
198198
$this->assertTrue($result);
199199
$this->assertFalse($this->schemaManager->hasCollection($collection));
200200
}
201+
202+
public function testCreateEdgeCollection()
203+
{
204+
$collection = 'relationships';
205+
206+
if ($this->schemaManager->hasCollection($collection)) {
207+
$this->schemaManager->deleteCollection($collection);
208+
}
209+
210+
$result = $this->schemaManager->createEdgeCollection($collection);
211+
212+
$this->assertEquals($collection, $result->name);
213+
$this->assertSame(3, $result->type);
214+
215+
$this->schemaManager->deleteCollection($collection);
216+
}
201217
}

0 commit comments

Comments
 (0)