npm install --save cushion-adapter-couchbase
var cushion = require('couch-cushion'),
adapter = require('cushion-adapter-couchbase');
cushion.install(adapter);
cushion.connect({ /* adapter config */ });
Configuration is initially done through the connect
function, which passes the
options on to the adapter.
{
host: undefined, // The host that the CB cluster is located on
bucket: 'default', // The bucket name to connect to
bucketPass: null, // If there is a password on the bucket
// Optional, timeouts for different operations.
// See CB docs for details
connectionTimeout: undefined,
opartionTimeout: undefined,
opartionTimeout: undefined,
managementTimeout: undefined,
// N1ql server endpoints to be enabled via:
// bucket.enableN1ql(/* ... */)
n1qlEndpoints: undefined,
}
The adapter can be setup to use Couchbase SDK's mock interface for testing.
var cushion = require('couch-cushion'),
adapter = require('cushion-adapter-couchbase');
cushion.install(adapter.Mock); // Install Mock adapter
cushion.connect({ /* adapter config */ });
After installing the Couchbase adapter a number of new properties and methods become available to the base CouchCushion object. The new methods and properties are to ease the process of communicating with Couchbase through the adapter.
Cb / Couchbase:
Allows access to the same Couchbase instance used by the adapter.
ex: cushion.Cb
/ cushion.Couchbase
Gets a single model from Couchbase using a query. The method accepts either an already constructed query or arguments that can be used to create a query. The result that is returned is the first doc that Couchbase returns.
Ex:
var cb = function(err, model, res) {
/* ... */
}
// Using a query
var query = cushion.CB.ViewQuery
.from('userDesignDoc', 'by_username')
.key('jfelsinger');
cushion.getOne('User', cb, query);
// Using parts of a query
cushion.getOne('User', cb, 'by_username', 'jfelsinger', 'userDesignDoc');
Same as above, but returns an array of objects.
Ex:
var cb = function(err, models, res) {
/* ... */
}
// Using a query
var query = cushion.CB.ViewQuery
.from('userDesignDoc', 'by_status')
.key('online');
cushion.getOne('User', cb, query);
// Using parts of a query
cushion.getMany('User', cb, 'by_status', 'online', 'userDesignDoc');
Gets an array of models from a query, much like getMany()
.
Ex:
// Using a query
var query = cushion.CB.ViewQuery
.from('userDesignDoc', 'by_status')
.key('online');
cushion.fromQuery('User', cb, query);
Gets a single model from a query, much like getOne()
.
Ex:
// Using a query
var query = cushion.CB.ViewQuery
.from('userDesignDoc', 'by_username')
.key('jfelsinger');
cushion.oneFromQuery('User', cb, query);
Gets an array of models from a view query, much like getMany()
.
Ex:
cushion.fromView('User', cb, 'by_status', 'online', 'userDesignDoc');
Gets a single model from a view query, much like getOne()
.
Ex:
cushion.oneFromView('User', cb, 'by_username', 'jfelsinger', 'userDesignDoc');
Gets the raw results of a query, similar to calling bucket.query
.
Ex:
// Using a view-query
var query = cushion.CB.ViewQuery
.from('userDesignDoc', 'by_username')
.key('jfelsinger');
cushion.rawQuery(query, cb);
// Using an n1ql query-string
query = "SELECT * FROM default WHERE name='test'";
cushion.rawQuery(query, cb);