CouchConf Tokyo Developing with Couchbase Part III

1,865 views

Published on

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,865
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
28
Comments
0
Likes
2
Embeds 0
No embeds

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 UI
    shows 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
  • CouchConf Tokyo Developing with Couchbase Part III

    1. 1. 1 Developing with Couchbase Part III: Advanced Application Development Matt Ingenthron Director, Developer Solutions
    2. 2. 5 THE QUERY API
    3. 3. 6 Querying with PHP – Custom View <?javascript // map function function(doc) { if(doc.name) { emit(doc.name); } } <?php include "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; }
    4. 4. 7 Querying with PHP – Custom View Reverse <?php include "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; }
    5. 5. 8 Querying with PHP – Custom View Key <?php include "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; }
    6. 6. 9 Querying with PHP – Custom View Key Range <?php include "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; }
    7. 7. 10 Querying with PHP – Custom View Key Range Limit <?php include "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; }
    8. 8. 11 USING THE QUERY API FOR CALCULATION
    9. 9. 12 Querying with PHP – Custom View <?javascript // map function function(doc) { if(doc.category) { emit(doc.category, 1); } } //reduce: _count <?php include "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; }
    10. 10. 13 View Calculation Result
    11. 11. 16 PAGING OVER VIEWS
    12. 12. 17 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; }
    13. 13. 18 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>';
    14. 14. 19 ERROR HANDLING
    15. 15. 20 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); }
    16. 16. 21 Error Handling <?php // ... skip setup $result = $cb->set("a", 1); if($result == false) { // something went wrong $code = $cb->getResultCode(); // lets find it switch($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; } }
    17. 17. 22 • Would be great if everything went perfectly in a cluster, but… – Node failures – System becomes overloaded – Temporary out of memory conditions Cluster Ready Error Handling
    18. 18. 23 Q&A

    ×