-
Notifications
You must be signed in to change notification settings - Fork 46
/
streaming-aql-query.php
54 lines (42 loc) · 1.55 KB
/
streaming-aql-query.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
<?php
namespace ArangoDBClient;
require __DIR__ . '/init.php';
try {
$connection = new Connection($connectionOptions);
$collectionHandler = new CollectionHandler($connection);
// set up a document collection "testCollection"
$collection = new Collection('testCollection');
try {
$collectionHandler->create($collection);
} catch (\Exception $e) {
// collection may already exist - ignore this error for now
//
// make sure it is empty
$collectionHandler->truncate($collection);
}
$statement = new Statement($connection, [
'query' => 'FOR i IN 1..10000 INSERT { _key: CONCAT("test", i) } INTO @@collection',
'bindVars' => [ '@collection' => 'testCollection' ],
]);
$statement->execute();
echo 'COUNT AFTER AQL INSERT: ' . $collectionHandler->count($collection) . PHP_EOL;
// next query has a potentially huge result - therefore set the "stream" flag
$statement = new Statement($connection, [
'query' => 'FOR doc IN @@collection RETURN doc',
'bindVars' => [ '@collection' => 'testCollection' ],
'stream' => true
]);
$cursor = $statement->execute();
$counter = 0;
foreach ($cursor as $document) {
++$counter;
print '- DOCUMENT KEY: ' . $document->getKey() . PHP_EOL;
}
print 'QUERY RETURNED ' . $counter . ' DOCUMENTS' . PHP_EOL;
} catch (ConnectException $e) {
print $e . PHP_EOL;
} catch (ServerException $e) {
print $e . PHP_EOL;
} catch (ClientException $e) {
print $e . PHP_EOL;
}