From af7c25e6ecdba24ac39d69a9d6535d4303ec9225 Mon Sep 17 00:00:00 2001 From: neru Date: Tue, 13 Jan 2026 18:36:40 -0300 Subject: [PATCH] style: run format:apply and cleanup unused imports --- src/modules/db.ts | 108 +++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/src/modules/db.ts b/src/modules/db.ts index e838352..2f896bd 100644 --- a/src/modules/db.ts +++ b/src/modules/db.ts @@ -1,75 +1,73 @@ import { - Attributes, - DataTypes, - Model, - ModelAttributes, - ModelStatic, - Sequelize + DataTypes, + Model, + ModelStatic, + Sequelize } from 'sequelize'; export class DatabaseManager { - private readonly db: Sequelize; + private readonly db: Sequelize; - public guildData: ModelStatic | null = null; - public userData: ModelStatic | null = null; + public guildData: ModelStatic | null = null; + public userData: ModelStatic | null = null; - private constructor() { - this.db = new Sequelize('db', 'luma', '', { - host: 'localhost', - dialect: 'sqlite', - storage: 'db.sqlite', - logging: false - }); + private constructor() { + this.db = new Sequelize('db', 'luma', '', { + host: 'localhost', + dialect: 'sqlite', + storage: 'db.sqlite', + logging: false + }); - this.db.sync(); - } + this.db.sync(); + } - public async init(userKeys: object, guildKeys: object) { - this.userData = this.db.define('user_data', { - user_id: { type: DataTypes.STRING, unique: true, primaryKey: true }, - ...userKeys - }); + public async init(userKeys: object, guildKeys: object) { + this.userData = this.db.define('user_data', { + user_id: { type: DataTypes.STRING, unique: true, primaryKey: true }, + ...userKeys + }); - this.guildData = this.db.define('guild_data', { - guild_id: { type: DataTypes.STRING, unique: true, primaryKey: true }, - ...guildKeys - }); + this.guildData = this.db.define('guild_data', { + guild_id: { type: DataTypes.STRING, unique: true, primaryKey: true }, + ...guildKeys + }); - await this.db.sync({ alter: true }); - } + await this.db.sync({ alter: true }); + } - public sync(): void { - this.db.sync(); - } + public sync(): void { + this.db.sync(); + } - public async getUser(userId: string) { - if (!this.userData) throw new Error("Database not initialized"); + public async getUser(userId: string) { + if (!this.userData) throw new Error('Database not initialized'); - const [user] = await this.userData.findOrCreate({ - where: { user_id: userId }, - defaults: { user_id: userId } - }); - return user; - } + const [user] = await this.userData.findOrCreate({ + where: { user_id: userId }, + defaults: { user_id: userId } + }); + return user; + } - public async getGuild(guildId: string) { - if (!this.guildData) throw new Error("Database not initialized"); + public async getGuild(guildId: string) { + if (!this.guildData) throw new Error('Database not initialized'); - const [guild] = await this.guildData.findOrCreate({ - where: { guild_id: guildId }, - defaults: { guild_id: guildId } - }); - return guild; - } + const [guild] = await this.guildData.findOrCreate({ + where: { guild_id: guildId }, + defaults: { guild_id: guildId } + }); + return guild; + } - /* + /* singleton logic */ - static #instance: DatabaseManager | null = null; + static #instance: DatabaseManager | null = null; - public static get get(): DatabaseManager { - if (!DatabaseManager.#instance) - DatabaseManager.#instance = new DatabaseManager(); - return DatabaseManager.#instance; - } + public static get get(): DatabaseManager { + if (!DatabaseManager.#instance) + DatabaseManager.#instance = new DatabaseManager(); + return DatabaseManager.#instance; + } }