我建立了服务器和数据库。我的问题是有关在数据库上运行的查询的问题:
app.get('/api/plan/download/:id', async (req, res) => {
try {
const {rows} = await client.query('select * from nova_schema.files where user_id = ' + req.id + ';');
res.send(rows);
} catch (ex) {
console.log('fail' + ex);
res.send('fail' + ex);
}
});
抛出错误“ failerror:“未定义”列不存在”
但这可行:
const {rows} = await client.query('select * from nova_schema.files where user_id = 1;');
我是新手,正在尝试学习。可能是什么问题?
非常感谢!
答案 0 :(得分:0)
您缺少req.params.id
只需将行更改为
const {rows} = await client.query('select * from nova_schema.files where user_id = ' + req.params.id + ';');