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.
Example:
// server/datasources.json
{
"lorem": {
"name": "cache", // the datasource name
"connector": "couchdb", // the connector name
"url": "${couchdbUrl}", // optional
"database": "lorem", // required
"designDocs": {} // optional
}
}
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); }"
}
}
}
}
}
}
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.