Beispiel #1
0
<?php

$options = array('host' => 'sync.renegde.com', 'port' => 80);
$db = new CouchDB($options);
$map = "function(doc) { emit(doc._id, doc);}";
$response = $db->temp_view($map);
print_r($response);
    /**
     * @expectedException Exception
     */
    public function testTempViewWithNoDatabaseOption()
    {
        $default = CouchDBTestConstants::kDefaultType;
        $update = CouchDBTestConstants::kUpdateType;
        $map = <<<FUNCTION
\t\tfunction(doc) 
\t\t{ 
\t\t\tif(doc.type == '{$default}' || doc.type == '{$update}')
\t\t\t{ 
\t\t\t\temit(doc._id, 1);
\t\t\t}
\t\t}
FUNCTION;
        $couchdb = new CouchDB();
        $couchdb->temp_view($map);
    }
 **/
/**
 * Sample
 */
require 'couchdb/CouchDB.php';
$newdb = 'newdb';
$options = array('database' => $newdb);
$db = new CouchDB($options);
/*
$map = <<<FUNCTION
function(doc)
{
	if(doc.type == 'category')
	{
		emit(doc._id, 1);
	}
}
FUNCTION;

$reduce = <<<FUNCTION
function(keys, values, rereduce)
{
	return sum(values);
}
FUNCTION;
*/
// EITHER WILL WORK
$map = "function(doc) { if(doc.type == 'category') { emit(doc._id, 1);}}";
$reduce = "function(keys, values, rereduce) { return sum(values); }";
$result = $db->temp_view($map, $reduce);
print_r($result);
Beispiel #4
0
 *
 *    Author: Adam Venturella - aventurella@gmail.com
 *
 *    @package Sample 
 *    @author Adam Venturella <*****@*****.**>
 *    @copyright Copyright (C) 2009 Adam Venturella
 *    @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 *
 **/
/**
 * Sample
 */
require 'couchdb/CouchDB.php';
$newdb = 'newdb';
$options = array('database' => $newdb);
$db = new CouchDB($options);
/*
$map = <<<FUNCTION
function(doc)
{
	if(doc.type == 'category')
	{
		emit(doc._id, doc);
	}
}
FUNCTION;
*/
// EITHER WILL WORK
$map = "function(doc) { if(doc.type == 'category') { emit(doc._id, doc);}}";
$result = $db->temp_view($map);
print_r($result);