loopback-connector-couchdb

0.3.0 • Public • Published

loopback-connector-couchdb

Build Status Coverage Status

What

A connector is used to connect Loopback models to a storage, and in this case, a CouchDB DB. See the official doc for Connecting models to data sources.

How to

Config

Example:

// server/datasources.json
{
  "lorem": {
    "name": "cache", // the datasource name
    "connector": "couchdb", // the connector name
    "url": "${couchdbUrl}", // optional
    "database": "lorem", // required
    "designDocs": {} // optional
  }
}

Install design docs

The designDocs that you put in the datasource config can be installed with autoupdate() or automigrate(). Example:

// server/datasources.json
{
  "lorem": {
    ...
    "designDocs": {
      "find": {
        "views": {
          "byName": {
            "map": "function(doc) { if (doc.name) emit(doc.name, null); }"
          }
        }
      }
    }
  }
}

Use a view

Example:

// Assuming you have a connector instance.
// Note that `connect()` returns a cached connection (singleton, promisified, wrapped in a Bluebird promise).
connector.connect().call('viewAsync', 'find', 'byName', { keys: ['Charlie'] }).then((res) => {
  res.should.be.Object();
  res.should.have.property('rows').which.is.Array().with.length(1);
});

See the tests for more examples.

Package Sidebar

Install

npm i loopback-connector-couchdb

Weekly Downloads

6

Version

0.3.0

License

MIT

Last publish

Collaborators

  • makara