This is the template project that's checked out and configured when you run the bando-up command from ljsthw-bandolier. This is where the code really lives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bandolier-template/api/admin/schema.js

22 lines
743 B

import { knex } from '../../lib/ormish.js';
import { API } from '../../lib/api.js';
export const get = async (req, res) => {
const api = new API(req, res);
if(!api.admin_authenticated) {
return api.error(401, "Admin rights required.");
} else {
// NOTE: in lib/ormish.js the schema is loaded once, but I do it every time
// here to reflect the current database even if they haven't restarted it yet
let result = await knex("sqlite_schema").where({"type": "table"}).select(['type', 'name']).orderBy('name');
for(let table of result) {
table._columns = await knex(table.name).columnInfo();
}
// TODO: flag that the database has changed so they know to restart
return api.reply(200, result);
}
}