Exemplo n.º 1
0
    //var_dump($response->getHeader()->getStatusCode());
    echo "Body<br>";
    if ($response->isError()) {
        echo '<div class="error">';
        var_dump($response->getBody(true));
        echo '</div>';
    } else {
        var_dump($response->getBody(true));
    }
    echo "<hr>";
}
define('LOCAL_CLASS_PATH', realpath('./') . '/');
set_include_path(get_include_path() . PATH_SEPARATOR . LOCAL_CLASS_PATH);
spl_autoload_register();
use net\servicehome\connector\couchdb as couch;
$connector = new couch\CouchDB();
echo "Test Connection";
$response_test = $connector->sendCommand(couch\CouchDB::createCommand(couch\CouchDB::CMD__TEST));
dump($response_test);
echo "Create a new Database";
$response_create_db = $connector->sendCommand(couch\CouchDB::createCommand(couch\CouchDB::CMD__CREATE_DATABASE, 'test_db'));
dump($response_create_db);
echo "Delete a database";
$response_delete_db = $connector->sendCommand(new couch\command\DeleteDatabase('db_name'));
dump($response_delete_db);
echo "List all databases";
$response_list_dbs = $connector->sendCommand(couch\CouchDB::createCommand(couch\CouchDB::CMD__LIST_ALL_DBS));
dump($response_list_dbs);
echo "Try to fetch document and create/update it";
$response_get_document = $connector->sendCommand(new couch\command\GetDocument('test_db', "setup"));
$document = $response_get_document->isOk() ? new couch\data\Document($response_get_document) : couch\data\Document::create('setup');
Exemplo n.º 2
0
<?php

define('LOCAL_CLASS_PATH', realpath('./') . '/');
set_include_path(get_include_path() . PATH_SEPARATOR . LOCAL_CLASS_PATH);
spl_autoload_register();
use net\servicehome\connector\couchdb as couch;
$connector = new couch\CouchDB();
//$view = new couch\data\View();
//$view->setId('test');
//$view->setView('with_test', array('map' => "function(doc) { if (doc.Type == 'Gemüse')  emit(doc.id, doc) }"));
//$response = $connector->sendCommand(new couch\command\CreateView('test_db', $view));
//var_dump($response);
$response = $connector->sendCommand(new couch\command\GetView("test_db", 'test'));
if ($response->isOk()) {
    $view = new couch\data\View($response);
    $view->setView('reduce_example', array('map' => "function(doc) { if (doc.Art == 'Obst')  emit(doc.Art, doc.Preis ) }", 'reduce' => "function (key, values) { return sum(values) }"));
    $response_update = $connector->sendCommand(new couch\command\UpdateView('test_db', $view));
    var_dump($response_update);
} else {
    var_dump($response);
}
Exemplo n.º 3
0
<?php

define('LOCAL_CLASS_PATH', realpath('./') . '/');
set_include_path(get_include_path() . PATH_SEPARATOR . LOCAL_CLASS_PATH);
spl_autoload_register();
use net\servicehome\connector\couchdb as couch;
$connector = new couch\CouchDB();
// CREATE DB
////////////////////////
$db_name = "test_db";
$response = $connector->sendCommand(new couch\command\CreateDatabase($db_name));
var_dump($response);
// CREATE sample entries
////////////////////////
$document = couch\data\Document::create("entry_a");
$document->set("Art", "Obst");
$document->set("Name", "Orange");
$document->set("Preis", 1.5);
$response = $connector->sendCommand(couch\command\CreateDocument::initWithDoc($db_name, $document));
var_dump($response);
$document->setId("entry_b");
$document->resetRevision();
$document->set("Art", "Obst");
$document->set("Name", "Apfel");
$document->set("Preis", 1.2);
$response = $connector->sendCommand(couch\command\CreateDocument::initWithDoc($db_name, $document));
var_dump($response);
$document->setId("entry_c");
$document->resetRevision();
$document->set("Art", "Obst");
$document->set("Name", "Birne");