我正在使用pg npm模块使用node.js和Postgres开发一个项目。当我运行查询时,查询不会执行,也不会返回错误。在邮递员上,它一直保持查询状态,并最终返回错误,表示无法得到任何响应。
static signUp(request, response) {
const userPass = passwordHelper.passwordHash(request.body.passwd.trim());
const query = {
text: 'INSERT INTO users(fullname, username, email, password) VALUES ($1, $2, $3, $4)',
values: [ request.body.fullname, request.body.username, request.body.email, userPass ],
}
client.query(query, (error, response) => {
if (error) {
return response.status(500).json({
status: 'Failed',
message: 'Could not create account!',
error,
});
} else {
const token = tokenHelper.generateToken(response.rows[0].id);
return response.status(200).json({
status: 'Success',
message: 'Acount created successfully',
token,
});
}
client.end();
});
}