Beispiel #1
0
 public function __construct($db_name, View $document)
 {
     $url = '/' . $db_name . '/' . $document->getId();
     $method = 'PUT';
     $data = $document->getJson();
     parent::__construct($url, $method, $data);
 }
<?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);
}
Beispiel #3
0
$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");
$document->set("Preis", 0.9);
$response = $connector->sendCommand(couch\command\CreateDocument::initWithDoc($db_name, $document));
var_dump($response);
$document->setId("entry_d");
$document->resetRevision();
$document->set("Art", "Gemüse");
$document->set("Name", "Möhre");
$document->set("Preis", 0.2);
$response = $connector->sendCommand(couch\command\CreateDocument::initWithDoc($db_name, $document));
var_dump($response);
$document->setId("entry_e");
$document->resetRevision();
$document->set("Art", "Gemüse");
$document->set("Name", "Tomate");
$document->set("Preis", 0.4);
$response = $connector->sendCommand(couch\command\CreateDocument::initWithDoc($db_name, $document));
var_dump($response);
// CREATE a view
////////////////////////
$view = new couch\data\View();
$view->setId("ansichten");
$view->setView("Obst", array('map' => "function(doc) { if (doc.Art == 'Obst')  emit(doc.Art, doc.Preis ) }", 'reduce' => "function (key, values) { return sum(values) }"));
$view->setView("Gemüse", array('map' => "function(doc) { if (doc.Art == 'Gemüse')  emit(doc.Art, {'Name':doc.Name, 'Preis':doc.Preis} ) }"));
$response = $connector->sendCommand(new couch\command\CreateView($db_name, $view));
var_dump($response);