diff --git a/package.json b/package.json index b5644d7..76e2180 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "3.0.0-cake.p240803b", + "version": "3.0.0-cake.p240814a", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/modules/database/model/learn.ts b/src/modules/database/model/learn.ts index 051885e..10ca1f6 100644 --- a/src/modules/database/model/learn.ts +++ b/src/modules/database/model/learn.ts @@ -4,19 +4,19 @@ import { Snowflake } from 'discord.js' import run from '../run' export class LearnTable implements BaseTable { - public name = 'learn' + public readonly name = 'learn' public constructor(private _database: Pool) {} public async all(): Promise { const [rows] = await this._database.execute( - 'SELECT * FROM learn;', + `SELECT * FROM ${this.name};`, ) return rows } public async findOne(key: string): Promise { const [rows] = await this._database.execute( - 'SELECT * FROM learn WHERE command = ?;', + `SELECT * FROM ${this.name} WHERE command = ?;`, [key], ) return rows @@ -31,7 +31,7 @@ export class LearnTable implements BaseTable { await run(db, async () => { await db.execute( - 'INSERT INTO learn (command, result, user_id) VALUES (?, ?, ?);', + `INSERT INTO ${this.name} (command, result, user_id) VALUES (?, ?, ?);`, [data.command, data.result, data.user_id], ) }) @@ -44,10 +44,10 @@ export class LearnTable implements BaseTable { const db = await this._database.getConnection() await run(db, async () => { - await db.execute('UPDATE learn SET result = ? WHERE command = ?;', [ - data.command, - data.result, - ]) + await db.execute( + `UPDATE ${this.name} SET result = ? WHERE command = ?;`, + [data.command, data.result], + ) }) } @@ -55,7 +55,7 @@ export class LearnTable implements BaseTable { const db = await this._database.getConnection() await run(db, async () => { - await db.execute('DELETE FROM learn WHERE id = ?;', [key]) + await db.execute(`DELETE FROM ${this.name} WHERE id = ?;`, [key]) }) } @@ -64,7 +64,7 @@ export class LearnTable implements BaseTable { data: any, ): Promise { const [rows] = await this._database.execute( - `SELECT * FROM learn WHERE ${key} = ?;`, + `SELECT * FROM ${this.name} WHERE ${key} = ?;`, [data], ) return rows diff --git a/src/modules/database/model/nsfwContent.ts b/src/modules/database/model/nsfwContent.ts index 180d526..4ffdaf5 100644 --- a/src/modules/database/model/nsfwContent.ts +++ b/src/modules/database/model/nsfwContent.ts @@ -3,20 +3,19 @@ import { type Pool } from 'mysql2/promise' import run from '../run' export class NSFWContentTable implements BaseTable { - public name = 'nsfw_content' - + public readonly name = 'nsfw_content' public constructor(private _database: Pool) {} public async all(): Promise { const [rows] = await this._database.execute( - 'SELECT * FROM nsfw_content;', + `SELECT * FROM ${this.name};`, ) return rows } public async findOne(key: number): Promise { const [rows] = await this._database.execute( - 'SELECT * FROM nsfw_content WHERE id = ?;', + `SELECT * FROM ${this.name} WHERE id = ?;`, [key], ) return rows @@ -27,7 +26,7 @@ export class NSFWContentTable implements BaseTable { await run(db, async () => { await db.execute( - 'INSERT INTO nsfw_content (text, persona) VALUES (?, ?);', + `INSERT INTO ${this.name} (text, persona) VALUES (?, ?);`, [data.text, data.persona], ) }) @@ -37,7 +36,7 @@ export class NSFWContentTable implements BaseTable { const db = await this._database.getConnection() await run(db, async () => { - await db.execute('UPDATE nsfw_content SET text = ? WHERE id = ?;', [ + await db.execute(`UPDATE ${this.name} SET text = ? WHERE id = ?;`, [ data.text, data.id, ]) @@ -48,7 +47,7 @@ export class NSFWContentTable implements BaseTable { const db = await this._database.getConnection() await run(db, async () => { - await db.execute('DELETE FROM nsfw_content WHERE id = ?;', [key]) + await db.execute(`DELETE FROM ${this} WHERE id = ?;`, [key]) }) } @@ -58,7 +57,7 @@ export class NSFWContentTable implements BaseTable { ): Promise { const [rows] = await this._database.execute( `SELECT * - FROM nsfw_content + FROM ${this.name} WHERE ${key} = ?;`, [data], ) diff --git a/src/modules/database/model/statement.ts b/src/modules/database/model/statement.ts index 1d3390d..0847204 100644 --- a/src/modules/database/model/statement.ts +++ b/src/modules/database/model/statement.ts @@ -3,19 +3,19 @@ import { type Pool } from 'mysql2/promise' import run from '../run' export class StatementTable implements BaseTable { - public name = 'statement' + public readonly name = 'statement' public constructor(private _database: Pool) {} public async all(): Promise { const [rows] = await this._database.execute( - 'SELECT * FROM statement;', + `SELECT * FROM ${this.name};`, ) return rows } public async findOne(key: number): Promise { const [rows] = await this._database.execute( - 'SELECT * FROM statement WHERE id = ?;', + `SELECT * FROM ${this.name} WHERE id = ?;`, [key], ) return rows @@ -30,7 +30,7 @@ export class StatementTable implements BaseTable { await run(db, async () => { await db.execute( - 'INSERT INTO statement (text, persona, in_response_to) VALUES (?, ?, ?);', + `INSERT INTO ${this.name} (text, persona, in_response_to) VALUES (?, ?, ?);`, [data.text, data.persona, data.in_response_to], ) }) @@ -40,7 +40,7 @@ export class StatementTable implements BaseTable { const db = await this._database.getConnection() await run(db, async () => { - await db.execute('UPDATE statement SET text = ? WHERE id = ?;', [ + await db.execute(`UPDATE ${this.name} SET text = ? WHERE id = ?;`, [ data.text, data.id, ]) @@ -51,7 +51,7 @@ export class StatementTable implements BaseTable { const db = await this._database.getConnection() await run(db, async () => { - await db.execute('DELETE FROM statement WHERE id = ?;', [key]) + await db.execute(`DELETE FROM ${this.name} WHERE id = ?;`, [key]) }) } @@ -68,7 +68,7 @@ export class StatementTable implements BaseTable { data: any, ): Promise { const [rows] = await this._database.execute( - `SELECT * FROM statement WHERE ${key} = ?;`, + `SELECT * FROM ${this.name} WHERE ${key} = ?;`, [data], ) return rows