Refactor to more consistent structure (e.g. "plugins")
This commit is contained in:
33
database.ts
33
database.ts
@@ -3,32 +3,41 @@ import {Model, Sequelize, STRING} from 'sequelize';
|
||||
import 'node:fs/promises';
|
||||
import {readFile} from 'node:fs';
|
||||
|
||||
export const sql = new Sequelize('sqlite://./blitzcrank.sqlite');
|
||||
export const sequelize = new Sequelize('sqlite://./blitzcrank.sqlite');
|
||||
|
||||
export class GuildSetting extends Model {
|
||||
// Discord ID for the Guild (server)
|
||||
declare guildId: string;
|
||||
// Name of the option
|
||||
declare key: string;
|
||||
// Value being set
|
||||
declare value?: string;
|
||||
}
|
||||
|
||||
GuildSetting.init(
|
||||
{
|
||||
guildId: {type: STRING},
|
||||
key: {type: STRING},
|
||||
value: {type: STRING},
|
||||
},
|
||||
{sequelize: sql},
|
||||
);
|
||||
|
||||
export async function initDb() {
|
||||
export async function initializeDatabase() {
|
||||
try {
|
||||
await sql.authenticate();
|
||||
await sequelize.authenticate();
|
||||
console.log('Connected to database');
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function initializeModels() {
|
||||
GuildSetting.init(
|
||||
{
|
||||
guildId: {type: STRING},
|
||||
key: {type: STRING},
|
||||
value: {type: STRING},
|
||||
},
|
||||
{sequelize},
|
||||
);
|
||||
}
|
||||
|
||||
export async function syncModels() {
|
||||
await GuildSetting.sync();
|
||||
}
|
||||
|
||||
export async function readSettingsFromFile(path: string) {
|
||||
readFile(path, async (err, data) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user