Example #1
0
<?php

/**
 * Currently all examples are in 1 file cuz this thing's nowhere near ready and
 * updating multiple files would be f*****g annoying.
 *
 * Eventually this will be split into multiple files... each hilighting a different feature
 */
require_once realpath(dirname(__FILE__)) . '/inc.php';
require_once 'Duckk/CouchDB.php';
require_once 'Duckk/CouchDB/Util.php';
$couchdb = new Duckk_CouchDB();
$randomDoc = "testing_" . substr(md5(microtime(true)), 0, 8);
print_r($couchdb->getAllDocuments('arin'));
print_r($couchdb->getAllDocumentsBySequence('arin'));
echo "------------ example doc put (id = {$randomDoc}) -------------------\n";
$doc = new Duckk_CouchDB_Document();
$doc->_id = $randomDoc;
print_r($couchdb->putDocument('arin', $doc));
echo "------------ test copying  -------------------\n";
print_r($couchdb->copyDocument('arin', "testing_16bd3b77", "testing_b3307897copy", "12-2566465478", "1-1053805331"));
echo "------------ delete the example doc ({$randomDoc}) -------------------\n";
print_r($couchdb->deleteDocument('arin', $doc->_id));
echo "------------ get my test document --------------\n";
print_r($couchdb->getDocument('arin', 'booya3'));
echo "------------LIST OF DATABASES---------------\n";
print_r($couchdb->getDatabases());
echo "------------ get rev info for my test document --------------\n";
print_r($couchdb->getDocumentRevisionList('arin', 'booya'));
echo "------------ get rev info for my test document --------------\n";
print_r($couchdb->getDocumentRevisionInfo('arin', 'booya'));
<?php

require_once realpath(dirname(__FILE__)) . '/inc.php';
require_once 'Duckk/CouchDB.php';
require_once 'Duckk/CouchDB/Util.php';
require_once 'Duckk/CouchDB/DesignDocument.php';
// Random setup
$couchdb = new Duckk_CouchDB();
$random = substr(md5(microtime()), 0, 4);
$database = "employees-{$random}";
// avoid name collissions w/ the md5 suffix
// create an employee db
$db = $couchdb->createDatabase($database);
p("created database: {$database}", $db);
// create a document for employee named "Arin Sarkissian"
$arin = new Duckk_CouchDB_Document();
$arin->_id = "employee1";
// you MUST specify an id
$arin->firstName = "Arin";
$arin->lastName = "Sarkissian";
$arin->title = "Software Engineer";
$arin->salary = 2500000;
// i wish
$arin->phone = "(900) 976-1212";
$putResult = $couchdb->putDocument($database, $arin);
p("Put employee Arin Sarkissian", $putResult);
// create another employee: John Doe
$john = new Duckk_CouchDB_Document();
$john->_id = "employee2";
// you MUST specify an id
$john->firstName = "John";