discord_bot/util/timer/convertTimerJSONToSQL.js
SileNce5k 5a4cfd0a5f
All checks were successful
CI / CI (push) Successful in 19s
Lint Codebase / eslint (push) Successful in 12s
Rename database table functions to be clearer
2024-11-06 01:44:16 +01:00

32 lines
1.1 KiB
JavaScript

const sqlite3 = require('sqlite3').verbose();
module.exports = async function () {
const timers = require('../../data/timers.json')
const db = new sqlite3.Database('data/database.db');
return new Promise((resolve, reject) => {
for (let i = 0; i < timers.length; i++) {
let user = timers[i].user;
let reminderTime = timers[i].reminderDate;
let channel = timers[i].channel;
let customMessage = timers[i].customMessage;
let hasPassed = false;
db.run(`INSERT INTO timers (
user,
reminderTime,
channel,
customMessage,
hasPassed
) VALUES (?, ?, ?, ?, ?)`, [user, reminderTime, channel, customMessage, hasPassed], function (error) {
if (error) {
console.error(`Error while converting timers.json to SQL: ${error}`)
reject(error);
}
})
}
db.close();
console.log("Converted timers.json to SQL successfully.");
resolve();
})
}