diff --git a/.gitignore b/.gitignore index d1319a2..2619d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules .env pnpm-lock* -dist \ No newline at end of file +dist +*.db +*.sqlite* \ No newline at end of file diff --git a/index.ts b/index.ts index 95b8cba..0aafccd 100644 --- a/index.ts +++ b/index.ts @@ -3,7 +3,7 @@ import { WebhookClient, EmbedBuilder, Embed } from 'discord.js'; import { Worker } from 'worker_threads'; import { asyncInterval, addNotation } from './src/helperFunctions'; import { string } from 'prismarine-nbt'; - +import { InitTable } from './src/sqlFunctions'; import { loadConfig } from './src/configLoader'; const config = loadConfig(); @@ -24,6 +24,7 @@ const bazaarPrice = { }; async function initialize() { + await InitTable(); const matches = process.env.WEBHOOK_URL.match(webhookRegex); if (!matches) return console.log(`[Main thread] Couldn't parse Webhook URL`); const webhook = new WebhookClient({ id: matches[1], token: matches[2] }); diff --git a/package.json b/package.json index 33e90aa..0ebb551 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "open": "^8.4.2", "prismarine-nbt": "^2.7.0", "socket.io": "^4.8.1", + "sqlite3": "^5.1.7", "toastify-js": "^1.12.0", "ts-node": "^10.9.2", "typescript": "^5.7.2" diff --git a/src/sqlFunctions.js b/src/sqlFunctions.ts similarity index 83% rename from src/sqlFunctions.js rename to src/sqlFunctions.ts index 0dc6c02..496642c 100644 --- a/src/sqlFunctions.js +++ b/src/sqlFunctions.ts @@ -1,4 +1,4 @@ -const sqlite3 = require('sqlite3').verbose(); +import sqlite3 from 'sqlite3'; //TODO // MUTEX functions for adding/removing/upsert @@ -28,7 +28,7 @@ async function InitTable() { db.close(); } } -function runQuery(db, query , params = []) { +function runQuery(db: sqlite3.Database, query: string, params: string[] = []) { return new Promise((resolve,reject) => { db.run(query, params, function (err) { if(err){ @@ -40,7 +40,7 @@ function runQuery(db, query , params = []) { }); }); } -function getQuery(db, query, params = []) { +function getQuery(db: sqlite3.Database, query: string, params: string[] = []) { return new Promise((resolve, reject) => { db.get(query, params, (err, row) => { if (err) { @@ -51,7 +51,7 @@ function getQuery(db, query, params = []) { }); }); } -function allQuery(db, query, params = []) { +function allQuery(db: sqlite3.Database, query: string, params: string[] = []) { return new Promise((resolve, reject) => { db.all(query, params, (err, rows) => { if (err) { @@ -63,6 +63,6 @@ function allQuery(db, query, params = []) { }); } -module.exports = { +export { InitTable } \ No newline at end of file