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')); $randomDBName = 'testing' . md5(microtime(true)); echo "------------CREATE A DB NAMED {$randomDBName} --------------\n"; var_dump($couchdb->createDatabase("{$randomDBName}")); echo "------------TRY TO CREATE {$randomDBName} again --------------\n"; $couchdb->createDatabase($randomDBName); echo "------------Compact {$randomDBName} --------------\n"; var_dump($couchdb->compactDatabase("{$randomDBName}")); echo "------------ Get info for {$randomDBName} --------------\n"; print_r($couchdb->getDatabaseInfo($randomDBName)); echo "------------DELETE A DB NAMED {$randomDBName} --------------\n"; var_dump($couchdb->deleteDatabase($randomDBName)); echo "------------TRY TO DELETE {$randomDBName} again --------------\n"; $couchdb->deleteDatabase($randomDBName); echo "------------ Get info for {$randomDBName} After deleting it --------------\n"; print_r($couchdb->getDatabaseInfo($randomDBName));
// you MUST specify an id $john->firstName = "John"; $john->lastName = "Doe"; $john->phone = "(900) 555-1212"; $john->title = "CTO"; $john->salary = 850000; $putResult = $couchdb->putDocument($database, $john); p("Put employee John Doe", $putResult); // GET the document for Arin Sarkissian p("Get Arin's Data", $couchdb->getDocument($database, 'employee1')); // change his job title and save the document again $arin->title = 'Sr Software Engineer'; $putResult = $couchdb->putDocument($database, $arin); p("Get Arin's Data after title change", $couchdb->getDocument($database, 'employee1')); // now create a view $designDoc = new Duckk_CouchDB_DesignDocument(); $designDoc->setId('empData'); $designDoc->addView('all', 'function(doc) { emit(null, doc.salary); }'); $designDoc->addView('totalPayroll', 'function(doc) { emit("salary", doc.salary); }', 'function(name, salary) { return sum(salary) }'); // PUT the view $resp = $couchdb->putDocument($database, $designDoc); p("PUT the design document", $resp); // run the "all" view we just put $viewResult = $couchdb->getDocument($database, $designDoc->_id . '/_view/all'); p("Result of the 'ALL' view", $viewResult); // run the "totalPayroll" view we just put $viewResult = $couchdb->getDocument($database, $designDoc->_id . '/_view/totalPayroll'); p("Result of the 'totalPayroll' view", $viewResult); // clean up after ourselves and delete the DB $delete = $couchdb->deleteDatabase($database); p("deleted database: {$database}", $db);