Permalink
Browse files

Refactored Javascript Code and Documentation.

Change-Id: I0fe52bb1e9442843baecf17c0316f2e0323c6960
Reviewed-on: http://review.couchbase.org/30195
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Brett Lawson <brett19@gmail.com>
  • Loading branch information...
1 parent 9423dd3 commit 6bfc6f199acaa0b202f1cdee77aa56f225d05307 @brett19 brett19 committed Nov 9, 2013
Showing with 2,106 additions and 1,635 deletions.
  1. +3 −3 .gitignore
  2. +24 −0 .jsdoc
  3. +25 −0 .jshintrc
  4. +11 −1 Makefile
  5. +56 −89 README.md
  6. +39 −0 lib/binding.js
  7. +1,669 −0 lib/connection.js
  8. +88 −1,262 lib/couchbase.js
  9. +0 −101 lib/http.js
  10. +186 −177 lib/viewQuery.js
  11. +5 −2 package.json
View
@@ -14,11 +14,11 @@
# The original file after running astyle:
*.orig
-
*~
/.lock-wscript
/build/
-/tests/config.json
/node_modules/
-/tests/CouchbaseMock.jar
+/docs/
+/test/CouchbaseMock.jar
+builderror.log
View
24 .jsdoc
@@ -0,0 +1,24 @@
+{
+ "tags": {
+ "allowUnknownTags": false
+ },
+ "source": {
+ "include": ["./lib/", "./README.md"],
+ "includePattern": ".+\\.js(doc)?$",
+ "excludePattern": "(^|\\/|\\\\)_"
+ },
+ "opts": {
+ "template": "../../node_modules/cb-jsdoc-tpl",
+ "destination": "./docs/",
+ "private": true
+ },
+ "plugins": [
+ "plugins/markdown"
+ ],
+ "markdown": {
+ "parser": "gfm"
+ },
+ "templates": {
+ "cleverLinks": true
+ }
+}
View
@@ -0,0 +1,25 @@
+{
+ "indent": 2,
+ "maxlen": 80,
+
+ "node" : true,
+
+ "bitwise": false,
+ "camelcase": false,
+ "curly": true,
+ "es5" : false,
+ "eqeqeq": true,
+ "forin": true,
+ "freeze": true,
+ "immed": true,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "noempty": true,
+ "nonew": true,
+ "quotmark": "single",
+ "undef": true,
+ "unused": false,
+ "strict": true,
+ "trailing": true
+}
View
@@ -22,9 +22,17 @@ install:
node_modules:
@npm install
-check: node_modules
+test: node_modules
./node_modules/mocha/bin/mocha
+lint: node_modules
+ ./node_modules/jshint/bin/jshint lib/*.js
+
+check: test lint
+
+docs: node_modules
+ node ./node_modules/jsdoc/jsdoc.js -c .jsdoc
+
reformat:
@astyle --mode=c \
--quiet \
@@ -41,3 +49,5 @@ reformat:
io/*.c io/*.h io/util/hexdump.c \
src/*.cc \
src/*.h
+
+.PHONY: all test clean docs
View
145 README.md
@@ -1,119 +1,86 @@
-# Couchnode - Fast and Native Node.JS Client for Couchbase
+# Couchbase Node.js Client
+This library allows you to connect to a Couchbase cluster from Node.js.
+It is a native Node.js module and uses the very fast libcouchbase library to
+handle communicating to the cluster over the Couchbase binary protocol.
-This library allows you to connect to a Couchbase cluster from node.js.
-It is very fast and utilizes the binary protocol via a native node.js
-addon.
+[![Build Status](http://cb.br19.com:86/buildStatus/icon?job=couchnode)](http://cb.br19.com:86/job/couchnode/)
-## Basic installation and usage
-To install this module, we'll assume you are using
-[NPM](https://npmjs.org). However it is not as simple as a regular
-JavaScript module, as it depends on the C-library for Couchbase
-clients, [libcouchbase](https://github.com/couchbase/libcouchbase).
-Libcouchbase also powers other dynamic language clients, such as Ruby
-and PHP, so if you've worked with those clients you should feel right
-at home.
+## Useful Links
-First, you must install libcouchbase (version 2.1 or greater)
+Source - http://github.com/couchbase/couchnode
-On a mac, you can use homebrew this should be as easy as running:
+Bug Tracker - http://www.couchbase.com/issues/browse/JSCBC
- brew install libcouchbase
+Couchbase Node.js Community - http://couchbase.com/communities/nodejs
-### Building from Git
-Since you're reading this README, we're assuming you're going to be building
-from source. In this case, `cd` into the source root directory and run
+## Installing
- npm install --debug
+To install the lastest release using npm, run:
+```
+npm install couchbase
+```
-If your libcouchbase prefix is not inside the linker path, you can pass the
-`--couchbase-root` option over to `npm` like so:
+To install the in development version directly from github, run:
+```
+npm install git+https://github.com/couchbase/couchnode.git
+```
- npm install --debug --couchbase-root=/sources/libcouchbase/inst
-Note that `--couchbase-root` also sets the `RPATH` flags and assumes you are
-using an `ELF`-based platform (i.e. not OS X). To build on OS X, edit the
-bindings.gyp to replace `-rpath` with the appropriate linker flags.
+## Introduction
+Connecting to a Couchbase bucket is as simple as creating a new Connection
+instance. Once you are connect, you may execute any of Couchbases' numerous
+operations against this connection.
-## API description
+Here is a simple example of instantiating a connection, setting a new document
+into the bucket and then retrieving its contents:
-### Connecting.
+```javascript
+ var couchbase = require('couchbase');
+ var db = new couchbase.Connection({bucket: "default"}, function(err) {
+ if (err) throw err;
-To use this module, first do:
+ db.set('testdoc', {name:'Frank'}, function(err, result) {
+ if (err) throw err;
-```javascript
- var Couchbase = require('couchbase');
- var cb = new Couchbase.Connection({bucket: "default"}, function(err) { });
-```
+ db.get('testdoc', function(err, result) {
+ if (err) throw err;
-Note that you do not need to wait for the connection callback in order to start
-performing operations.
+ console.log(result.value);
+ // {name: Frank}
+ });
+ });
+ });
+```
-### Dealing with keys and values
-For API illustration, the best bet at the current time is [a small
-example http hit
-counter](https://github.com/couchbase/couchnode/tree/master/example.js). There
-is also [the test suite which shows more details.]
-(https://github.com/couchbase/couchnode/tree/master/tests)
+## Documentation
-The basic method summary is:
+An extensive documentation is available on the Couchbase website. Visit our
+[Node.js Community](http://couchbase.com/communities/nodejs) on
+the [Couchbase](http://couchbase.com) website for the documentation as well as
+numerous examples and samples.
-```javascript
- cb.get(key, function (err, result) {
- console.log("Value for key is: " + result.value);
- });
- cb.set(key, value, function (err, result) {
- console.log("Set item for key with CAS: " + result.cas);
- });
+## Source Control
- // Then the similar methods of add, replace, append, prepend:
- cb.add(key, value, function (err, result) {});
- cb.replace(key, value, function (err, result) {});
- cb.append(key, value, function (err, result) {});
- cb.prepend(key, value, function (err, result) {});
+The source code is available at
+[https://github.com/couchbase/couchnode](https://github.com/couchbase/couchnode).
+Once you have cloned the repository, you may contribute changes through our
+gerrit server. For more details see
+[CONTRIBUTING.md](https://github.com/couchbase/couchnode/blob/master/CONTRIBUTING.md).
- // Increment or decrement a numeric value:
- cb.incr(key, { delta: 42, initial: 20 }, function(err, result) {
- console.log("New value for counter is: " + result.value);
- });
- cb.decr(key, { delta: 99, default: 1024 }, function (err, result) {});
-
- // Remove items
- cb.remove(key, function (err, result));
-
- // Set multiple items:
- cb.setMulti({
- key1: { value: value1 },
- // You can set per-key options, like expiry as well.
- key2: { value: value2, expiry: 1000 } },
-
- // Use the "spooled" option to ensure the callback is invoked only once
- // with the result for all the items.
- { expiry: 300, spooled: true },
- function (err, results) {
- console.dir(results);
- }
- );
-
- // Get multiple items:
- // Note we don't pass options and don't use spooled, so the callback is
- // invoked for each key.
- cb.getMulti(["key1", "key2", "key3"], null, function(err, result) {
- console.log("Got result for key.. " + result.value);
- });
-```
+To execute our test suite, run `make test` from your checked out root directory.
-## Running Tests
-To run the unit tests built into the Node.js driver. Make sure you have
-mocha installed globally on your system, then execute mocha in the root
-directory of your couchnode installation.
+## License
+Copyright 2013 Couchbase Inc.
-## Contributing changes
+Licensed under the Apache License, Version 2.0.
-See CONTRIBUTING.md
+See
+[LICENSE](https://github.com/couchbase/couchnode/blob/master/LICENSE)
+for further details.
View
@@ -0,0 +1,39 @@
+'use strict';
+
+/**
+ * Attempts to load a binding by path ignoring not-found errors.
+ *
+ * @param {string} path The path to the binding to attempt loading.
+ * @returns {Object}
+ *
+ * @ignore
+ */
+function tryLoadBinding(path) {
+ try {
+ return require('bindings')(path);
+ } catch(e) {
+ if (!e.message.match(/Could not load the bindings file/)) {
+ throw e;
+ }
+ }
+ return null;
+}
+
+/**
+ * @type {{CouchbaseImpl:Object,Constants:Object}}
+ * @ignore
+ */
+var couchnode = tryLoadBinding('couchbase_impl');
+if (!couchnode) {
+ // Try to load prebuilt windows binaries
+ if (process.arch === 'x64') {
+ couchnode = tryLoadBinding('../prebuilt/win/x64/couchbase_impl');
+ } else if (process.arch === 'ia32') {
+ couchnode = tryLoadBinding('../prebuilt/win/ia32/couchbase_impl');
+ }
+}
+if (!couchnode) {
+ throw new Error('Failed to locate couchnode native binding');
+}
+
+module.exports = couchnode;
Oops, something went wrong.

0 comments on commit 6bfc6f1

Please sign in to comment.