Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Created March 7, 2018 20:27
Show Gist options
  • Save nsfmc/a43d6d6d0a689aa4610e9634fffd9797 to your computer and use it in GitHub Desktop.
Save nsfmc/a43d6d6d0a689aa4610e9634fffd9797 to your computer and use it in GitHub Desktop.
a bad couch implementation
const request = require('superagent');
class CouchClient {
constructor(db, host='http://localhost:5984') {
this.host = host;
this.db = db;
}
view(designDoc, viewName, opts = {}) {
return request
.get(`${this.host}/${this.db}/_design/${designDoc}/_view/${viewName}`, opts)
.query(opts)
.then(({res: {text}}) => JSON.parse(text));
}
get(docId) {
return request
.get(`${this.host}/${this.db}/${docId}`)
.then(({res: {text}}) => JSON.parse(text));
}
}
module.exports = {
default: CouchClient,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment