try { $collectionHandler->add($collection); } catch (\Exception $e) { // collection may already exist - ignore this error for now } // set up an edge collection to link the two previous collections $collection = new Collection("worksFor"); $collection->setType(3); try { $collectionHandler->add($collection); } catch (\Exception $e) { // collection may already exist - ignore this error for now } // create a new department $marketing = Document::createFromArray(array("name" => "Marketing")); $documentHandler->save("departments", $marketing); // create another department $finance = Document::createFromArray(array("name" => "Finance")); $documentHandler->save("departments", $finance); // create a new employee $john = Document::createFromArray(array("name" => "John")); $documentHandler->save("employees", $john); // create another employee $jane = Document::createFromArray(array("name" => "Jane")); $documentHandler->save("employees", $jane); // now insert a link between Marketing and Jane $worksFor = Edge::createFromArray(array("startDate" => "2009-06-23", "endDate" => "2014-11-12")); $edgeHandler->saveEdge("worksFor", $marketing->getHandle(), $jane->getHandle(), $worksFor); // now insert a link between Finance and Jane $worksFor = Edge::createFromArray(array("startDate" => "2014-11-12")); $edgeHandler->saveEdge("worksFor", $finance->getHandle(), $jane->getHandle(), $worksFor);
/** * Try to create and delete a document using a defined key */ public function testCreateAndDeleteDocumentUsingDefinedKeyWithArrayAndSaveOnly() { $connection = $this->connection; $collection = $this->collection; $documentHandler = new DocumentHandler($connection); $documentArray = array('someAttribute' => 'someValue', '_key' => 'frank01'); $documentId = $documentHandler->save($collection->getName(), $documentArray); $resultingDocument = $documentHandler->get($collection->getName(), $documentId); $resultingAttribute = $resultingDocument->someAttribute; $resultingKey = $resultingDocument->getKey(); $this->assertTrue($resultingAttribute === 'someValue', 'Resulting Attribute should be "someValue". It\'s :' . $resultingAttribute); $this->assertTrue($resultingKey === 'frank01', 'Resulting Attribute should be "someValue". It\'s :' . $resultingKey); $documentHandler->deleteById($collection->getName(), $documentId); }
try { $connection = new Connection($connectionOptions); $collectionHandler = new CollectionHandler($connection); $handler = new DocumentHandler($connection); // set up a document collection "users" $collection = new Collection("users"); try { $collectionHandler->add($collection); } catch (\Exception $e) { // collection may already exist - ignore this error for now } // create a new document $user = new Document(); $user->set("name", "John"); $user->age = 19; $id = $handler->save("users", $user); // get documents by example $cursor = $collectionHandler->byExample("users", array("name" => "John", "age" => 19)); var_dump($cursor->getAll()); // get the ids of all documents in the collection $result = $handler->getAllIds("users"); var_dump($result); // create another new document $user = new Document(); $user->set("name", "j-lo"); $user->level = 1; $user->vists = array(1, 2, 3); $id = $handler->save("users", $user); var_dump("CREATED A NEW DOCUMENT WITH ID: ", $id); // get this document from the server $userFromServer = $handler->getById("users", $id);