diff --git a/docs/schema-collections.md b/docs/schema-collections.md index d36fe25..4c7fc1c 100644 --- a/docs/schema-collections.md +++ b/docs/schema-collections.md @@ -52,6 +52,12 @@ Create a collection $arangoClient->schema()->createCollection('users'); ``` +### createEdgeCollection(string $name, array $config = [], $waitForSyncReplication = null, $enforceReplicationFactor = null): stdClass +Create an Edge collection +``` +$arangoClient->schema()->createEdgeCollection('relationships'); +``` + ### updateCollection(string $name, array $config = []): stdClass Update a collection ``` diff --git a/src/Schema/ManagesCollections.php b/src/Schema/ManagesCollections.php index d76be75..c9ebfc3 100644 --- a/src/Schema/ManagesCollections.php +++ b/src/Schema/ManagesCollections.php @@ -165,6 +165,26 @@ public function createCollection( return $this->arangoClient->request('post', '/_api/collection', $options); } + /** + * @param string $name + * @param array $config + * @param int|bool|null $waitForSyncReplication + * @param int|bool|null $enforceReplicationFactor + * @return stdClass + * + * @throws ArangoException + */ + public function createEdgeCollection( + string $name, + array $config = [], + $waitForSyncReplication = null, + $enforceReplicationFactor = null + ): stdClass { + $config['type'] = 3; + + return $this->createCollection($name, $config, $waitForSyncReplication, $enforceReplicationFactor); + } + /** * @param string $name * @param array $config diff --git a/tests/SchemaManagerCollectionsTest.php b/tests/SchemaManagerCollectionsTest.php index 92a74c6..b021c31 100644 --- a/tests/SchemaManagerCollectionsTest.php +++ b/tests/SchemaManagerCollectionsTest.php @@ -198,4 +198,20 @@ public function testCreateCollectionWithOptions() $this->assertTrue($result); $this->assertFalse($this->schemaManager->hasCollection($collection)); } + + public function testCreateEdgeCollection() + { + $collection = 'relationships'; + + if ($this->schemaManager->hasCollection($collection)) { + $this->schemaManager->deleteCollection($collection); + } + + $result = $this->schemaManager->createEdgeCollection($collection); + + $this->assertEquals($collection, $result->name); + $this->assertSame(3, $result->type); + + $this->schemaManager->deleteCollection($collection); + } }