-
Notifications
You must be signed in to change notification settings - Fork 46
/
edge.php
73 lines (57 loc) · 2.45 KB
/
edge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace ArangoDBClient;
require __DIR__ . '/init.php';
try {
$connection = new Connection($connectionOptions);
$collectionHandler = new CollectionHandler($connection);
$documentHandler = new DocumentHandler($connection);
$edgeHandler = new EdgeHandler($connection);
// set up two document collections
$collection = new Collection('employees');
try {
$collectionHandler->create($collection);
} catch (\Exception $e) {
// collection may already exist - ignore this error for now
}
$collection = new Collection('departments');
try {
$collectionHandler->create($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->create($collection);
} catch (\Exception $e) {
// collection may already exist - ignore this error for now
}
// create a new department
$marketing = Document::createFromArray(['name' => 'Marketing']);
$documentHandler->save('departments', $marketing);
// create another department
$finance = Document::createFromArray(['name' => 'Finance']);
$documentHandler->save('departments', $finance);
// create a new employee
$john = Document::createFromArray(['name' => 'John']);
$documentHandler->save('employees', $john);
// create another employee
$jane = Document::createFromArray(['name' => 'Jane']);
$documentHandler->save('employees', $jane);
// now insert a link between Marketing and Jane
$worksFor = Edge::createFromArray(['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(['startDate' => '2014-11-12']);
$edgeHandler->saveEdge('worksFor', $finance->getHandle(), $jane->getHandle(), $worksFor);
// now insert a link between Finance and John
$worksFor = Edge::createFromArray(['startDate' => '2012-04-01']);
$edgeHandler->saveEdge('worksFor', $finance->getHandle(), $john->getHandle(), $worksFor);
} catch (ConnectException $e) {
print $e . PHP_EOL;
} catch (ServerException $e) {
print $e . PHP_EOL;
} catch (ClientException $e) {
print $e . PHP_EOL;
}