dashboard-core/HandlerIntegration/index.js

26 lines
703 B
JavaScript
Raw Permalink Normal View History

2023-06-22 19:36:52 +05:00
const prefix = "[DBD-Storage-Handler]";
const Keyv = require("keyv");
const { join } = require("path");
2023-06-19 12:35:11 +05:00
class Handler {
2023-06-22 19:36:52 +05:00
constructor(keyvAdapter) {
this.db = new Keyv(keyvAdapter || `sqlite://${join(__dirname, "/database.sqlite")}`);
2023-06-19 12:35:11 +05:00
2023-06-22 19:36:52 +05:00
this.db.on("error", (err) => console.error(`${prefix} ${`Keyv connection error: ${err}`.red}`));
2023-06-19 12:35:11 +05:00
2023-06-22 19:36:52 +05:00
this.Category = require(`${__dirname}/structures/Category`)(this.db);
this.Option = require(`${__dirname}/structures/Option`)(this.db);
2023-06-19 12:35:11 +05:00
2023-06-22 19:36:52 +05:00
console.log(`${prefix} Database successfully initialized!`);
}
2023-06-19 12:35:11 +05:00
2023-06-22 19:36:52 +05:00
async fetch(guildId, optionId) {
return await this.db.get(`${guildId}.options.${optionId}`);
}
2023-06-19 12:35:11 +05:00
2023-06-22 19:36:52 +05:00
db() {
return this.db;
}
2023-06-19 12:35:11 +05:00
}
2023-06-22 19:36:52 +05:00
module.exports = Handler;