Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Couchbase SF Node.js SDK Slides

Avatar for Brett19 Brett19
September 13, 2013

Couchbase SF Node.js SDK Slides

Avatar for Brett19

Brett19

September 13, 2013

Other Decks in Programming

Transcript

  1. Presenta9on  Summary   •  Couchbase  Node.js  Client  Overview   • 

    Basic  Opera9ons   •  View  Opera9ons   •  Troubleshoo9ng  &  Error  Handling  
  2. Node.js  Client  Library  Basics     •  Implemented on top

    of libcouchbase with a C++ binding layer between Node.js and libcouchbase. •  Release 1.0.0-beta of Couchnode! •  Apache 2.0 License open source project -  http://github.com/couchbase/couchnode/ •  Easy, automatic installation through the NPM Registry: shell> npm install couchbase
  3. GeHng  Started   var couchbase = require("couchbase"); var bucket =

    new couchbase.Connection({ bucket:"default", password:"", host:"localhost:8091" }); bucket.set("foo", "val", function(err, result) { bucket.get("foo", function(err, result) { }); });
  4. Loading  Documents   bucket.get("foo", function(err, result) { console.log(result.value); }); bucket.getMulti(["foo",

    "bar"], function(err, results) { for(var key in results) console.log(results[key].value); });
  5. Muta9ng  Documents   bucket.set("foo", "value", function(err, result) { ... });

    bucket.add("foo", "heart", function(err, result) { ... }); bucket.setMulti({ "foo": {value:"foo_value"}, "bar": {value:"bar_value"} }, function(err, results) { ... });
  6. View  Querying   bucket.view("beer", "brewery_beers").query({ limit: 10, key: ['abba'] },

    function(err, results) { bucket.getMulti(results, function(geterr, getresults) { console.log(getresults); }); });
  7. Opera7on  Errors   •  All callbacks have the potential to

    return an error as their first parameter: bucket.add("foo", "heart", function(err, result) { if(err && err.code == couchbase.errors.keyAlreadyExists) { // Uh oh... Key already exists. Lets ignore it. return; } console.log(err); });
  8. Connec7on  Errors   •  Additionally, it is possible that serious

    errors, not specific to a particular operation will be emitted by the Connection itself: var bucket = new couchbase.Connection(); bucket.on('error', function(err) { console.log(err); });