58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
use ArangoDBClient\Collection;
|
|
use ArangoDBClient\CollectionHandler;
|
|
use ArangoDBClient\Connection;
|
|
use ArangoDBClient\ConnectionOptions;
|
|
use ArangoDBClient\DocumentHandler;
|
|
use ArangoDBClient\UpdatePolicy;
|
|
|
|
require "vendor/autoload.php";
|
|
include "config.php";
|
|
|
|
$connectionOptions = array(
|
|
// server endpoint to connect to
|
|
//ConnectionOptions::OPTION_ENDPOINT => 'tcp://10.16.17.154:8529',
|
|
ConnectionOptions::OPTION_ENDPOINT => 'tcp://' . $server . ':8529',
|
|
// authorization type to use (currently supported: 'Basic')
|
|
ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
|
|
// user for basic authorization
|
|
ConnectionOptions::OPTION_AUTH_USER => $dbuser,
|
|
// password for basic authorization
|
|
ConnectionOptions::OPTION_AUTH_PASSWD => $passwd,
|
|
// connection persistence on server. can use either 'Close' (one-time connections) or 'Keep-Alive' (re-used connections)
|
|
ConnectionOptions::OPTION_CONNECTION => 'Close',
|
|
// connect timeout in seconds
|
|
ConnectionOptions::OPTION_TIMEOUT => 3,
|
|
// whether or not to reconnect when a keep-alive connection has timed out on server
|
|
ConnectionOptions::OPTION_RECONNECT => true,
|
|
// optionally create new collections when inserting documents
|
|
ConnectionOptions::OPTION_CREATE => true,
|
|
// optionally create new collections when inserting documents
|
|
ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST,
|
|
ConnectionOptions::OPTION_DATABASE => $database,
|
|
);
|
|
|
|
// open connection
|
|
$connection = new Connection($connectionOptions);
|
|
$collectionHandler = new CollectionHandler($connection);
|
|
$documentHandler = new DocumentHandler($connection);
|
|
|
|
$collections = array(
|
|
"users" => Collection::TYPE_DOCUMENT,
|
|
"questions" => Collection::TYPE_DOCUMENT,
|
|
"answers" => Collection::TYPE_DOCUMENT,
|
|
"answered" => Collection::TYPE_EDGE,
|
|
"answeredQuestion" => Collection::TYPE_EDGE
|
|
);
|
|
|
|
foreach (array_keys($collections) as $c) {
|
|
$collection = new Collection($c);
|
|
$collection->setType($collections[$c]);
|
|
try {
|
|
$collectionHandler->create($collection);
|
|
echo 'creating collection ' . $c . "\n";
|
|
} catch (\Exception $e) {
|
|
echo 'collection ' . $c . " already exists\n";
|
|
}
|
|
} |