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

30 lines
664 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 => {
2020-04-08 17:57:27 +02:00
const databaseName = ctx.request.body.name;
await couchdb.db.create(databaseName);
2020-04-08 17:57:27 +02:00
await couchdb.db.use(databaseName).insert({
views: {
by_type: {
map: function(doc) {
emit([doc.type], doc._id);
}
}
}
}, '_design/database');
2020-04-08 17:57:27 +02:00
ctx.body = {
2020-04-08 17:57:27 +02:00
message: `Database ${databaseName} successfully provisioned.`,
status: 200
}
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;