@churchapps/apihelper
Version:
Library of helper functions not specific to any one ChurchApps project or framework.
43 lines • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DBCreator = void 0;
const dotenv_1 = __importDefault(require("dotenv"));
const fs_1 = __importDefault(require("fs"));
const DB_1 = require("./DB");
class DBCreator {
static async init(selectedTables) {
dotenv_1.default.config();
const todo = [];
selectedTables.forEach(async (st) => {
this.tables.forEach(async (t) => {
if (t.title === st)
todo.push(t);
});
});
for (const td of todo)
await this.runScript(td.title, "./src/tools/dbScripts/" + td.file, false);
return;
}
static async runScript(title, file, customDelimeter) {
console.log("Creating '" + title + "'");
const sql = fs_1.default.readFileSync(file, "utf-8");
let del = /;(?=END)\s*$|;(?!\nEND)\s*$/gm;
if (customDelimeter) {
del = /\$\$$/gm;
}
const statements = sql.split(del);
for (const statement of statements)
if (statement.length > 3)
await DB_1.DB.query(statement, []);
}
}
exports.DBCreator = DBCreator;
DBCreator.tables = [
{ title: "Links", file: "links.mysql" },
{ title: "Pages", file: "pages.mysql" },
{ title: "Settings", file: "settings.mysql" }
];
//# sourceMappingURL=DBCreator.js.map