bugfix for sql setup

main
june moretz 2023-05-07 00:07:05 -04:00
parent f21c44abd4
commit 989ea77e84
1 changed files with 9 additions and 5 deletions

14
db.js
View File

@ -1,6 +1,6 @@
const sqlite3 = require("sqlite3"); const sqlite3 = require("sqlite3");
const fs = require('fs'); const fs = require("fs");
const db = new sqlite3.Database('vybe.db'); const db = new sqlite3.Database("vybe.db");
db.query = function (sql, params) { db.query = function (sql, params) {
var that = this; var that = this;
@ -13,11 +13,15 @@ db.query = function (sql, params) {
}; };
(async () => { (async () => {
if (!fs.existsSync('vybe.db')) { if (!fs.existsSync("vybe.db")) {
console.log(fs.readFileSync('db/1-init.sql').toString().split(';')) for (let sql of fs
for(let sql of fs.readFileSync('db/1-init.sql').toString().split(';')) .readFileSync("db/1-init.sql")
.toString()
.split(";")
.filter((x) => x)) {
await db.query(sql); await db.query(sql);
} }
}
})(); })();
module.exports = db; module.exports = db;