sql: javascript > typescript
This commit is contained in:
parent
c3badac626
commit
d44ad19efc
4 changed files with 11 additions and 7 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,4 +1,6 @@
|
||||||
node_modules
|
node_modules
|
||||||
.env
|
.env
|
||||||
pnpm-lock*
|
pnpm-lock*
|
||||||
dist
|
dist
|
||||||
|
*.db
|
||||||
|
*.sqlite*
|
3
index.ts
3
index.ts
|
@ -3,7 +3,7 @@ import { WebhookClient, EmbedBuilder, Embed } from 'discord.js';
|
||||||
import { Worker } from 'worker_threads';
|
import { Worker } from 'worker_threads';
|
||||||
import { asyncInterval, addNotation } from './src/helperFunctions';
|
import { asyncInterval, addNotation } from './src/helperFunctions';
|
||||||
import { string } from 'prismarine-nbt';
|
import { string } from 'prismarine-nbt';
|
||||||
|
import { InitTable } from './src/sqlFunctions';
|
||||||
import { loadConfig } from './src/configLoader';
|
import { loadConfig } from './src/configLoader';
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ const bazaarPrice = {
|
||||||
};
|
};
|
||||||
|
|
||||||
async function initialize() {
|
async function initialize() {
|
||||||
|
await InitTable();
|
||||||
const matches = process.env.WEBHOOK_URL.match(webhookRegex);
|
const matches = process.env.WEBHOOK_URL.match(webhookRegex);
|
||||||
if (!matches) return console.log(`[Main thread] Couldn't parse Webhook URL`);
|
if (!matches) return console.log(`[Main thread] Couldn't parse Webhook URL`);
|
||||||
const webhook = new WebhookClient({ id: matches[1], token: matches[2] });
|
const webhook = new WebhookClient({ id: matches[1], token: matches[2] });
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"open": "^8.4.2",
|
"open": "^8.4.2",
|
||||||
"prismarine-nbt": "^2.7.0",
|
"prismarine-nbt": "^2.7.0",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
|
"sqlite3": "^5.1.7",
|
||||||
"toastify-js": "^1.12.0",
|
"toastify-js": "^1.12.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.7.2"
|
"typescript": "^5.7.2"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
import sqlite3 from 'sqlite3';
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
// MUTEX functions for adding/removing/upsert
|
// MUTEX functions for adding/removing/upsert
|
||||||
|
@ -28,7 +28,7 @@ async function InitTable() {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function runQuery(db, query , params = []) {
|
function runQuery(db: sqlite3.Database, query: string, params: string[] = []) {
|
||||||
return new Promise((resolve,reject) => {
|
return new Promise((resolve,reject) => {
|
||||||
db.run(query, params, function (err) {
|
db.run(query, params, function (err) {
|
||||||
if(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) => {
|
return new Promise((resolve, reject) => {
|
||||||
db.get(query, params, (err, row) => {
|
db.get(query, params, (err, row) => {
|
||||||
if (err) {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
db.all(query, params, (err, rows) => {
|
db.all(query, params, (err, rows) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -63,6 +63,6 @@ function allQuery(db, query, params = []) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
InitTable
|
InitTable
|
||||||
}
|
}
|
Loading…
Reference in a new issue