Cushion Adapter Couchbase
An adapter for connecting to a Couchbase DB through Couch-cushion
Installation
npm install --save cushion-adapter-couchbase
var cushion = adapter = ; cushion;cushion;
Configuration
Configuration is initially done through the connect
function, which passes the
options on to the adapter.
Configuration Options
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
Mock Interface
The adapter can be setup to use Couchbase SDK's mock interface for testing.
var cushion = adapter = ; cushion; // Install Mock adaptercushion;
Couch Cushion Methods and Properties
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.
Properties
Cb / Couchbase:
Allows access to the same Couchbase instance used by the adapter.
ex: cushion.Cb
/ cushion.Couchbase
Methods
CouchCushion.getOne(model, cb, search[, key[, doc[, db]]])
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 { /* ... */} // Using a queryvar query = cushionCBViewQuery ; cushion; // Using parts of a querycushion;
CouchCushion.getMany(model, cb, search[, key[, doc[, db]]])
Same as above, but returns an array of objects.
Ex:
var { /* ... */} // Using a queryvar query = cushionCBViewQuery ; cushion; // Using parts of a querycushion;
CouchCushion.fromQuery(model, cb, query[, db])
Gets an array of models from a query, much like getMany()
.
Ex:
// Using a queryvar query = cushionCBViewQuery ; cushion;
CouchCushion.oneFromQuery(model, cb, query[, db])
Gets a single model from a query, much like getOne()
.
Ex:
// Using a queryvar query = cushionCBViewQuery ; cushion;
CouchCushion.fromView(model, cb, view, key, doc[, db[, isMultiKey]])
Gets an array of models from a view query, much like getMany()
.
Ex:
cushion;
CouchCushion.oneFromView(model, cb, view, key, doc[, db[, isMultiKey]])
Gets a single model from a view query, much like getOne()
.
Ex:
cushion;
CouchCushion.rawQuery(query, cb[, *db])
Gets the raw results of a query, similar to calling bucket.query
.
Ex:
// Using a view-queryvar query = cushionCBViewQuery ; cushion; // Using an n1ql query-stringquery = "SELECT * FROM default WHERE name='test'"; cushion;