首先,对不起我的英语。 我是nodejs中api的初学者,我正在使用Express框架和一些打字稿制作的api,一切正常,但在更新或删除查询后无法控制受影响的行数。
我知道我可以使用“ res.affectedRows”来做到这一点,但是在我尝试使用该方法的情况下,我收到以下消息:“ Response类型上不存在受属性影响的行”。 对如何解决这个问题有帮助吗?
import { Request, Response} from 'express';
import db from '../database';
class GamesController {
public async delete (req: Request, res: Response): Promise<void> {
const { id } = req.params;
await db.query('DELETE FROM game WHERE id = ?',[id]);
//res.affectedRows <----
//Here is where i have the error message
//I'd just try to change the type of res from Response to any
//but it doesn't helps
res.json({message: 'Game deleted'});
}
public async update (req: Request, res: Response): Promise<void> {
const { id } = req.params;
await db.query('UPDATE game SET ? WHERE id = ?',[req.body, id]);
res.json({message: 'Game updated'});
}
}
const gamesController = new GamesController();
export default gamesController;