Intro to CouchDB by Sam Bisbee
Hi! CTO – Woopid.com
Maintain CouchDB for Debian
Sag (CouchDB for PHP) http://www.saggingcouch.com
sam@sbisbee.com || @sbisbee
Happy Birthday! CouchDB turned 1.0 last week!
NoSQL Explained in  1 [Snarky] Line $qry = sprintf("SELECT registration.*,company.name as companyName,address.lineOne as companyAddress,address.city as companyCity,address.state as companyState,address.zip as companyZip,mealsAttending.*,needHotel.* FROM registration,company,address,mealsAttending,needHotel WHERE registration.email='%s' AND registration.company=company.id AND company.address=address.id AND registration.mealsAttending=mealsAttending.id AND registration.needHotel=needHotel.id", self::clean($email));
NoSQL Explained in 1 Word CHOICE
There isn't much PHP tonight That's a good thing!
But here's some: try { //Get the post (a StdClass)... $post = $this->sag->get('postID')->body; //...update its info... $post->views++; //..and send it back to the couch. return $this->sap->put($post->_id, $post)->body->ok; } catch(SagCouchException $e) { //The requested post doesn't exist - oh no! if($e->getCode() == "404") $e = new Exception("That post doesn't exist."); throw $e; }
CAP Theorem You can only have 2 of these 3... Consistency  – everyone has the same data at the same time
Availability  – it's okay if nodes go down
Partition Tolerance  – message loss is okay
CAP Theorem Credit: CouchDB The Definitive Guide (http://books.couchdb.org)
JSON Javascript Object Notation Null: null
String: “bwah”
Int/Float: 3.33
Booleans: true
Object: { “key”: “value” }
Array: [ “element, “element” ]
JSON & PHP json_encode(array(“hi”, 1, false)); json_decode($jsonString); $class = new UserVO(); json_encode($class);
CouchDB “Defined” Document based
Stores everything in JSON
RESTful API over HTTP
Query with Map/Reduce in a language of your choice (usually JavaScript)
Wait, document based? Everything is a document
Stored as JSON (a class)
No more schemas! YAY!
Documents can have attachments
Wait, document based? {   “name”: “Sam Bisbee”,   “company”: “Woopid”,   “twitter”: “@sbisbee”,   “rsvp”: true,   “talks”: [ 1, 5, 10 ] }
RESTful API CRUD operations C reate  POST /databaseName/   PUT /databaseName/docID
R ead  GET /databaseName/docID
U pdate  PUT /databaseName/docID
D elete  DELETE /databaseName/docID
Get it... $response =    $sag->get('/32 character hash'); $httpHeaders = $response->headers; $document = $response->body;
...and set it $result = $sag->put(   $document->_id,   $document   ); if($result->body->ok)   return true; else   throw new Exception('Nope!');
Design Documents & Futon Design Documents hold your queries (Map/Reduce, list and show functions, etc.)

Intro to CouchDB