From 4c65794b6c6c47bc77ddd5b64ca336f670ad52cb Mon Sep 17 00:00:00 2001 From: Migan178 Date: Thu, 30 Nov 2023 13:07:54 +0900 Subject: [PATCH] feat: add findOneAnotherKey --- package.json | 2 +- src/modules/database/model/learn.ts | 11 +++++++++++ src/modules/database/model/nsfwContent.ts | 11 +++++++++++ src/modules/database/model/statement.ts | 19 +++++++++++++++++++ src/modules/database/type.ts | 1 + 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ef395af..775abd7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffin-ai-arujak", - "version": "2.0.0-75-oreo", + "version": "2.0.0-77-oreo", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/modules/database/model/learn.ts b/src/modules/database/model/learn.ts index 57e7af9..a32e569 100644 --- a/src/modules/database/model/learn.ts +++ b/src/modules/database/model/learn.ts @@ -58,4 +58,15 @@ export class LearnTable implements BaseTable { await db.execute('DELETE FROM learn WHERE command = ?;', [key]) }) } + + public async findOneAnotherKey( + key: 'command' | 'result' | 'user_id' | 'created_at', + data: any, + ): Promise { + const [rows] = await this._database.execute( + 'SELECT * FROM learn WHERE ? = ?;', + [key, data], + ) + return rows + } } diff --git a/src/modules/database/model/nsfwContent.ts b/src/modules/database/model/nsfwContent.ts index 948f15a..9c6e895 100644 --- a/src/modules/database/model/nsfwContent.ts +++ b/src/modules/database/model/nsfwContent.ts @@ -54,4 +54,15 @@ export class NSFWContentTable implements BaseTable { await db.execute('DELETE FROM nsfw_content WHERE id = ?;', [key]) }) } + + public async findOneAnotherKey( + key: 'id' | 'text' | 'persona' | 'created_at', + data: any, + ): Promise { + const [rows] = await this._database.execute( + 'SELECT * FROM nsfw_content WHERE ? = ?;', + [key, data], + ) + return rows + } } diff --git a/src/modules/database/model/statement.ts b/src/modules/database/model/statement.ts index 4bebaab..6fe258a 100644 --- a/src/modules/database/model/statement.ts +++ b/src/modules/database/model/statement.ts @@ -55,4 +55,23 @@ export class StatementTable implements BaseTable { await db.execute('DELETE FROM statement WHERE id = ?;', [key]) }) } + + public async findOneAnotherKey( + key: + | 'id' + | 'text' + | 'persona' + | 'created_at' + | 'search_text' + | 'conversation' + | 'in_response_to' + | 'search_in_response_to', + data: any, + ): Promise { + const [rows] = await this._database.execute( + 'SELECT * FROM statement WHERE ? = ?;', + [key, data], + ) + return rows + } } diff --git a/src/modules/database/type.ts b/src/modules/database/type.ts index f625c53..8a1b3e9 100644 --- a/src/modules/database/type.ts +++ b/src/modules/database/type.ts @@ -31,4 +31,5 @@ export interface BaseTable { insert(data: any): Promise update(data: any): Promise delete(key: V): Promise + findOneAnotherKey(key: string, data: any): Promise }