Your SlideShare is downloading. ×
0
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Portland Developing Couchbase Part III:  Advanced App Dev
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Portland Developing Couchbase Part III: Advanced App Dev

513

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
513
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
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

    ×