DB: Switch to better-sqlite3
This commit is contained in:
25
core/db.js
25
core/db.js
@@ -1,20 +1,21 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const sqlite3 = require("sqlite3").verbose();
|
const Database = require("better-sqlite3");
|
||||||
|
const path = require("path");
|
||||||
const { open } = require('sqlite');
|
const { open } = require('sqlite');
|
||||||
const filepath = "./data/minzbot.db";
|
const filepath = "./data/minzbot.db";
|
||||||
|
|
||||||
async function createDbConnection() {
|
async function createDbConnection() {
|
||||||
if (fs.existsSync(filepath)) {
|
const dir = path.dirname(filepath);
|
||||||
//new sqlite3.Database(filepath);
|
if (!fs.existsSync(dir)) {
|
||||||
const db = await open({filename: filepath, driver: sqlite3.Database});
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
await initDB(db);
|
|
||||||
return db;
|
|
||||||
} else {
|
|
||||||
const db = await open({filename: filepath, driver: sqlite3.Database});
|
|
||||||
await initDB(db);
|
|
||||||
console.log("[DATABASE] Connection with SQLite has been established");
|
|
||||||
return db;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const db = new Database(filepath, { verbose: console.log });
|
||||||
|
|
||||||
|
initDB(db);
|
||||||
|
|
||||||
|
console.log("[DATABASE] Connection with better-sqlite3 established");
|
||||||
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initDB(db) {
|
async function initDB(db) {
|
||||||
@@ -36,4 +37,4 @@ async function initDB(db) {
|
|||||||
console.log('[DATABASE] Created new DB table');
|
console.log('[DATABASE] Created new DB table');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = createDbConnection();
|
module.exports = createDbConnection;
|
||||||
8
main.js
8
main.js
@@ -2,8 +2,11 @@ const fs = require('node:fs');
|
|||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { Client, Collection, Events, GatewayIntentBits, Options, Partials } = require('discord.js');
|
const { Client, Collection, Events, GatewayIntentBits, Options, Partials } = require('discord.js');
|
||||||
const { token } = require('./config.json');
|
const { token } = require('./config.json');
|
||||||
|
const createDbConnection = require('./core/db.js');
|
||||||
|
|
||||||
const localDB = require('./core/db');
|
|
||||||
|
async function entrypoint() {
|
||||||
|
const localDB = await createDbConnection();
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessageReactions],
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessageReactions],
|
||||||
@@ -64,3 +67,6 @@ client.on(Events.ClientReady, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
};
|
||||||
|
|
||||||
|
entrypoint();
|
||||||
|
|||||||
1007
package-lock.json
generated
1007
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.8",
|
"axios": "^1.6.8",
|
||||||
|
"better-sqlite3": "^12.6.2",
|
||||||
"discord.js": "^14.13.0",
|
"discord.js": "^14.13.0",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"spotify-web-api-node": "^5.0.2",
|
"spotify-web-api-node": "^5.0.2",
|
||||||
"sqlite": "^5.1.1",
|
"sqlite": "^5.1.1"
|
||||||
"sqlite3": "^5.1.7"
|
|
||||||
},
|
},
|
||||||
"name": "minzbot",
|
"name": "minzbot",
|
||||||
"description": "Successor of the Discord.py implementation",
|
"description": "Successor of the Discord.py implementation",
|
||||||
|
|||||||
Reference in New Issue
Block a user