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

28 lines
689 B
JavaScript
Raw Normal View History

2020-04-07 16:12:08 +02:00
const couchdb = require("../../db");
2020-04-09 17:53:48 +02:00
exports.create = async function(ctx) {
const databaseName = ctx.request.body.name;
await couchdb.db.create(databaseName);
await couchdb.db.use(databaseName).insert({
views: {
by_type: {
map: function(doc) {
emit([doc.type], doc._id);
}
2020-04-09 17:53:48 +02:00
}
}
2020-04-09 17:53:48 +02:00
}, '_design/database');
ctx.body = {
message: `Instance Database ${databaseName} successfully provisioned.`,
status: 200
2020-04-07 16:12:08 +02:00
}
2020-04-09 17:53:48 +02:00
};
2020-04-07 16:12:08 +02:00
2020-04-09 17:53:48 +02:00
exports.destroy = async function(ctx) {
await couchdb.db.destroy(ctx.params.databaseId)
ctx.body = {
message: `Instance Database ${ctx.params.databaseId} successfully destroyed.`,
status: 200
}
};