budibase/packages/server/middleware/controllers/database.js

29 lines
670 B
JavaScript
Raw Normal View History

2020-04-07 16:12:08 +02:00
const couchdb = require("../../db");
const controller = {
fetch: async ctx => {
},
2020-04-07 16:12:08 +02:00
create: async ctx => {
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;