Skip to content

Instantly share code, notes, and snippets.

@cefn
Last active April 5, 2020 13:18
Show Gist options
  • Save cefn/8ef16aa522c208d4d2877f2d40359a45 to your computer and use it in GitHub Desktop.
Save cefn/8ef16aa522c208d4d2877f2d40359a45 to your computer and use it in GitHub Desktop.
Uploads design docs to couchdb through nano for Component testing within views
const {
Loader
} = require("./designdocs/loader")
class CouchdbConfigurator{
constructor(dbHandle){
if( //duck-type check for nano db handle
typeof dbHandle === "object" &&
typeof dbHandle.config === "object" &&
dbHandle.config.url &&
dbHandle.config.db ){
this.dbHandle = dbHandle
}
else{
throw "Constructor expects couchdb handle created like: nano(url).use(dbName)"
}
}
getDbName(){
return this.dbHandle.config.db
}
async createDb(){
return await this.dbHandle.server.db.create(this.getDbName())
}
async insertDesignDocs(){
const loader = new Loader()
const docs = loader.loadDesignDocs()
for(const doc of docs){
await this.dbHandle.insert(doc)
}
}
async destroyDb(){
return await this.dbHandle.server.db.destroy(this.getDbName())
}
}
module.exports = {
CouchdbConfigurator
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment