Created
March 7, 2018 20:27
-
-
Save nsfmc/a43d6d6d0a689aa4610e9634fffd9797 to your computer and use it in GitHub Desktop.
a bad couch implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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