Skip to content

Instantly share code, notes, and snippets.

@cefn

cefn/configurator.js

Last active Apr 5, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.