1

我正在使用 mysql2 包。我在节点中做简单的 sql 查询。那为什么会转

public async getTests(req: Request, res: Response): Promise<void> { 
        const pool = await connect(); 
        const stmt = 'SELECT test, test2 FROM testTable';
        const tests = await pool.query(stmt);  
        res.json({ tests});
}

查询结果:

{ foo,foo1 },列定义 { _buf:<缓冲区 01 00 00 01 0a 51 00 00 02 03 64 65 66 13 61 75 72 6f 72 61 5f 61 75 64 69 74 5f 73 69 67 6e 61 6c 6 0a 66 67 65 6d 65 6e 74 0a 65 6e 67 61 67 ... 1200 更多字节>,

4

1 回答 1

2

查询函数返回字段。请尝试获取行:

    const [rows] = await pool.query(stmt);  

您可以查看以下链接了解详情。 https://github.com/sidorares/node-mysql2#using-promise-wrapper

于 2021-10-18T22:28:32.320 回答