Portland Developing Couchbase Part III:  Advanced App Dev
 

Portland Developing Couchbase Part III: Advanced App Dev

on

  • 750 views

 

Statistics

Views

Total Views
750
Views on SlideShare
750
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • make JS code screenshot of admin UI or show admin UI
  • descending = true
  • All beers with "A”
  • All beers with "A", first 10.Pagination: later in the deck
  • make JS code screenshot of admin UI or show admin UIshows categories with their respective beer count.
  • TBD: make product screenshot
  • All beers with "A", 10 per page, first page.
  • All beers with "A", 10 per page, more pages.
  • More Details, many more, see the docs

Portland Developing Couchbase Part III:  Advanced App Dev Portland Developing Couchbase Part III: Advanced App Dev Presentation Transcript

  • Developing with Couchbase Part III: Advanced Application Development John Zablocki Developer Advocate @codevoyeur 1
  • THE QUERY API 5
  • Querying with PHP – Custom View<?javascript// map functionfunction(doc) { if(doc.name) { emit(doc.name); }}<?phpinclude "Couchbase.php";$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$view = $cb->getView("beer/names"); // "custom" view$result = $view->query();foreach($result AS $row) { echo $row->key . ": " . $row->value;} 6
  • Querying with PHP – Custom View Reverse<?phpinclude "Couchbase.php";$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$view = $cb->getView("beer/names");$result = $view->query(array( "descending" => true));foreach($result AS $row) { echo $row->key . ": " $row->value;} 7
  • Querying with PHP – Custom View Key<?phpinclude "Couchbase.php";$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$view = $cb->getView("beer/names");$result = $view->query(array( "key" => "Hoptimus Prime"));foreach($result AS $row) { echo $row->key . ": " $row->value;} 8
  • Querying with PHP – Custom View Key Range<?phpinclude "Couchbase.php";$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$view = $cb->getView("beer/names");$result = $view->query(array( "startkey" => "A", "endkey" => "B"));foreach($result AS $row) { echo $row->key . ": " $row->value;} 9
  • Querying with PHP – Custom View Key Range Limit<?phpinclude "Couchbase.php";$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$view = $cb->getView("beer/names");$result = $view->query(array( "startkey" => "A", "endkey" => "B", "limit" => 10));foreach($result AS $row) { echo $row->key . ": " $row->value;} 10
  • USING THE QUERY API FOR CALCULATION 11
  • Querying with PHP – Custom View<?javascript// map functionfunction(doc) { if(doc.category) { emit(doc.category, 1); }}//reduce: _count<?phpinclude "Couchbase.php";$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$view = $cb->getView("beer/categories"); // "custom" view$result = $view->query(array("group" => true));foreach($result AS $row) { echo $row->key . ": " $row->value;} 12
  • View Calculation Result 13
  • PAGING OVER VIEWS 16
  • Querying with PHP – Custom View Pagination<?php$view = $cb->getView("beer/names");$resultPages = $view->getResultPaginator();$resultPages->setRowsPerPage(10);$resultPages->setOptions(array( "startkey" => "A", "endkey" => "B");foreach($resultPages AS $row) { echo $row->key . ": " $row->value;} 17
  • Querying with PHP – Custom View Pagination<?php$view = $cb->getView("beer/names");$pageKey = $_GET["pageKey"]; // URL ESCAPE!$resultPages = $view->getResultPaginator();$resultPages->setPageKey($pageKey);$resultPages->setRowsPerPage(10);$resultPages->setOptions(array( "startkey" => "A", "endkey" => "B");foreach($resultPages AS $row) { echo $row->key . ": " $row->value;}$pageKey = $resultPages->key();echo <a href="?pageKey= . $pageKey. ">Next</a>; 18
  • ERROR HANDLING 19
  • Error Handling<?php// ... skip setup$cb->set("a", 1); // Silent Oops.$result = $cb->set("a", 1);if($result == false) { $code = $cb->getResultCode(); echo $cb->getResultMessage($code);} 20
  • Error Handling<?php// ... skip setup$result = $cb->set("a", 1);if($result == false) { // something went wrong $code = $cb->getResultCode(); // lets find itswitch($code) { case COUCHBASE::RES_HOST_LOOKUP_FAILURE: echo "DNS lookup to Server failed"; break; case COUCHBASE::RES_UNKNOWN_READ_FAILURE: echo "Failed to read from network"; break; case COUCHBASE::RES_WRITE_FAILURE: echo "Failed to read from network"; break; case COUCHBASE:RES_TIMEOUT: echo "Operation timed out"; break;}} 21
  • Cluster Ready Error Handling• Would be great if everything went perfectly in a cluster, but… – Node failures – System becomes overloaded – Temporary out of memory conditions 22
  • Q&A 23