feat: add findOneAnotherKey

This commit is contained in:
Siwoo Jeon 2023-11-30 13:07:54 +09:00
parent e217fb29fc
commit 4c65794b6c
Signed by: migan
GPG key ID: C4151385FFD2082A
5 changed files with 43 additions and 1 deletions

View file

@ -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": {

View file

@ -58,4 +58,15 @@ export class LearnTable implements BaseTable<LearnData, string> {
await db.execute('DELETE FROM learn WHERE command = ?;', [key])
})
}
public async findOneAnotherKey(
key: 'command' | 'result' | 'user_id' | 'created_at',
data: any,
): Promise<LearnData[]> {
const [rows] = await this._database.execute<LearnData[]>(
'SELECT * FROM learn WHERE ? = ?;',
[key, data],
)
return rows
}
}

View file

@ -54,4 +54,15 @@ export class NSFWContentTable implements BaseTable<NSFWData, number> {
await db.execute('DELETE FROM nsfw_content WHERE id = ?;', [key])
})
}
public async findOneAnotherKey(
key: 'id' | 'text' | 'persona' | 'created_at',
data: any,
): Promise<NSFWData[]> {
const [rows] = await this._database.execute<NSFWData[]>(
'SELECT * FROM nsfw_content WHERE ? = ?;',
[key, data],
)
return rows
}
}

View file

@ -55,4 +55,23 @@ export class StatementTable implements BaseTable<ResponseData, number> {
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<ResponseData[]> {
const [rows] = await this._database.execute<ResponseData[]>(
'SELECT * FROM statement WHERE ? = ?;',
[key, data],
)
return rows
}
}

View file

@ -31,4 +31,5 @@ export interface BaseTable<T, V> {
insert(data: any): Promise<void>
update(data: any): Promise<void>
delete(key: V): Promise<void>
findOneAnotherKey(key: string, data: any): Promise<T[]>
}