2020-04-07 16:12:08 +02:00
|
|
|
const couchdb = require("../../db");
|
|
|
|
|
|
|
|
const controller = {
|
2020-04-08 12:18:30 +02:00
|
|
|
fetch: async ctx => {
|
|
|
|
|
|
|
|
},
|
2020-04-07 16:12:08 +02:00
|
|
|
create: async ctx => {
|
2020-04-08 12:18:30 +02:00
|
|
|
const databaseName = ctx.request.body.databaseName;
|
|
|
|
await couchdb.db.create(databaseName);
|
|
|
|
const db = couchdb.db.use(databaseName)
|
|
|
|
await db.insert({
|
|
|
|
views: {
|
|
|
|
by_type: {
|
|
|
|
map: function(doc) {
|
|
|
|
emit([doc.type], doc._id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, '_design/database');
|
|
|
|
ctx.body = {
|
|
|
|
message: `Database ${databaseName} successfully provisioned.`
|
|
|
|
}
|
2020-04-07 16:12:08 +02:00
|
|
|
},
|
|
|
|
destroy: async ctx => {
|
2020-04-07 18:25:09 +02:00
|
|
|
ctx.body = await couchdb.db.destroy(ctx.params.databaseName)
|
2020-04-07 16:12:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = controller;
|