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 fs = require('fs');
const db = new sqlite3.Database('vybe.db');
const fs = require("fs");
const db = new sqlite3.Database("vybe.db");
db.query = function (sql, params) {
var that = this;
@ -13,10 +13,14 @@ db.query = function (sql, params) {
};
(async () => {
if (!fs.existsSync('vybe.db')) {
console.log(fs.readFileSync('db/1-init.sql').toString().split(';'))
for(let sql of fs.readFileSync('db/1-init.sql').toString().split(';'))
if (!fs.existsSync("vybe.db")) {
for (let sql of fs
.readFileSync("db/1-init.sql")
.toString()
.split(";")
.filter((x) => x)) {
await db.query(sql);
}
}
})();