• Like

Portland Developing Couchbase Part III: Advanced App Dev

  • 470 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
470
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
5
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • 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

Transcript

  • 1. Developing with Couchbase Part III: Advanced Application Development John Zablocki Developer Advocate @codevoyeur 1
  • 2. THE QUERY API 5
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. USING THE QUERY API FOR CALCULATION 11
  • 9. 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
  • 10. View Calculation Result 13
  • 11. PAGING OVER VIEWS 16
  • 12. 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
  • 13. 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
  • 14. ERROR HANDLING 19
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. Q&A 23