This commit is contained in:
Siwoo Jeon 2023-02-08 21:44:38 +09:00
parent 12fe84bb2d
commit a70711902a
Signed by: migan
GPG key ID: C4151385FFD2082A
3 changed files with 9 additions and 5 deletions

View file

@ -7,7 +7,9 @@ export default class extends Command {
} }
public async execute(msg: Message, args: string[]) { public async execute(msg: Message, args: string[]) {
const conn = await database.getConnection() const conn = await database.getConnection()
const [rows] = await conn.query<ResponseData[]>('SELECT * FROM statement;') const [rows] = await conn.execute<ResponseData[]>(
'SELECT * FROM statement;'
)
const muffin: ResponseData[] = [] const muffin: ResponseData[] = []
rows.forEach(row => { rows.forEach(row => {
if (row.persona === 'muffin') muffin.push(row) if (row.persona === 'muffin') muffin.push(row)

View file

@ -6,7 +6,9 @@ export default class ChatBot {
const conn = await database.getConnection() const conn = await database.getConnection()
const request = msg.content.replace('머핀아 ', '') const request = msg.content.replace('머핀아 ', '')
console.log(`req: ${request}`) console.log(`req: ${request}`)
const [rows] = await conn.query<ResponseData[]>('SELECT * FROM statement;') const [rows] = await conn.execute<ResponseData[]>(
'SELECT * FROM statement;'
)
let response = rows[Math.floor(Math.random() * rows.length)].text let response = rows[Math.floor(Math.random() * rows.length)].text
if (!response) response = '살ㄹ려주세요' if (!response) response = '살ㄹ려주세요'
console.log(`res: ${response}`) console.log(`res: ${response}`)
@ -20,7 +22,7 @@ export default class ChatBot {
const conn = await database.getConnection() const conn = await database.getConnection()
if (msg.author.id === '1026185545837191238') { if (msg.author.id === '1026185545837191238') {
const response = await this.getResponse(msg) const response = await this.getResponse(msg)
const [rows] = await conn.query<ResponseData[]>( const [rows] = await conn.execute<ResponseData[]>(
'SELECT * FROM statement;' 'SELECT * FROM statement;'
) )
try { try {

View file

@ -4,9 +4,9 @@ import { createConnection } from 'mysql2/promise'
describe('test database system', () => { describe('test database system', () => {
test('Validate rows', async () => { test('Validate rows', async () => {
return database.getConnection().then(async conn1 => { return database.getConnection().then(async conn1 => {
const [rows1] = await conn1.query('SELECT * FROM statement;') const [rows1] = await conn1.execute('SELECT * FROM statement;')
const conn2 = await createConnection(config) const conn2 = await createConnection(config)
const [rows2] = await conn2.query(`SELECT * FROM statement;`) const [rows2] = await conn2.execute(`SELECT * FROM statement;`)
expect(rows1).toEqual(rows2) expect(rows1).toEqual(rows2)
}) })
}) })