|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ArangoDBClient; |
| 4 | + |
| 5 | +require __DIR__ . '/init.php'; |
| 6 | + |
| 7 | +/* set up some example statements */ |
| 8 | +$statements = [ |
| 9 | + 'FOR u IN users RETURN u' => null, |
| 10 | + 'FOR u IN users FILTER u.id == @id RETURN u' => ['id' => 6], |
| 11 | + 'FOR u IN users FILTER u.id == @id && u.name != @name RETURN u' => ['id' => 1, 'name' => 'fox'], |
| 12 | +]; |
| 13 | + |
| 14 | + |
| 15 | +try { |
| 16 | + $connection = new Connection($connectionOptions); |
| 17 | + $collectionHandler = new CollectionHandler($connection); |
| 18 | + $documentHandler = new DocumentHandler($connection); |
| 19 | + |
| 20 | + // set up a document collection "testCollection" |
| 21 | + $collection = new Collection('users'); |
| 22 | + try { |
| 23 | + $collectionHandler->create($collection); |
| 24 | + } catch (\Exception $e) { |
| 25 | + // collection may already exist - ignore this error for now |
| 26 | + // |
| 27 | + // make sure it is empty |
| 28 | + $collectionHandler->truncate($collection); |
| 29 | + } |
| 30 | + |
| 31 | + $docs = [ |
| 32 | + Document::createFromArray(['name' => 'foo', 'id' => 1]), |
| 33 | + Document::createFromArray(['name' => 'bar', 'id' => 2]), |
| 34 | + Document::createFromArray(['name' => 'baz', 'id' => 3]), |
| 35 | + Document::createFromArray(['name' => 'fox', 'id' => 4]), |
| 36 | + Document::createFromArray(['name' => 'qaa', 'id' => 5]), |
| 37 | + Document::createFromArray(['name' => 'qux', 'id' => 6]), |
| 38 | + Document::createFromArray(['name' => 'quu', 'id' => 7]), |
| 39 | + ]; |
| 40 | + foreach ($docs as $doc) { |
| 41 | + $documentHandler->save($collection, $doc); |
| 42 | + } |
| 43 | + |
| 44 | + foreach ($statements as $query => $bindVars) { |
| 45 | + $statement = new Statement($connection, [ |
| 46 | + 'query' => $query, |
| 47 | + 'count' => true, |
| 48 | + 'batchSize' => 1000, |
| 49 | + 'bindVars' => $bindVars, |
| 50 | + 'sanitize' => true, |
| 51 | + ] |
| 52 | + ); |
| 53 | + |
| 54 | + echo 'RUNNING STATEMENT ' . $statement . PHP_EOL; |
| 55 | + |
| 56 | + $cursor = $statement->execute(); |
| 57 | + foreach ($cursor->getAll() as $doc) { |
| 58 | + echo '- RETURN VALUE: ' . json_encode($doc) . PHP_EOL; |
| 59 | + } |
| 60 | + |
| 61 | + echo PHP_EOL; |
| 62 | + } |
| 63 | +} catch (ConnectException $e) { |
| 64 | + print $e . PHP_EOL; |
| 65 | +} catch (ServerException $e) { |
| 66 | + print $e . PHP_EOL; |
| 67 | +} catch (ClientException $e) { |
| 68 | + print $e . PHP_EOL; |
| 69 | +} |
0 commit comments