Postgres Nodejs:行值更新不正确



我在数据库中有这个表:

CREATE TABLE "public"."feedback" (
"id" int4 NOT NULL DEFAULT nextval('feedback_id_seq'::regclass),
"title" text NOT NULL,
"description" text,
"created_on" timestamp NOT NULL DEFAULT now(),
"category" text NOT NULL,
"assignee_nickname" text DEFAULT 'unassigned'::text,
PRIMARY KEY ("id")
);

服务器上的此设置:

const updateAssign = (req, res) => {
const assignee = req.body.assignee
const feedbackId = req.params.id
pool.query('UPDATE feedback SET assignee_nickname = $1 WHERE id = $2 RETURNING *', [assignee, feedbackId], (err, result) => {
if (err) console.log(err);
res.status(200).send(result.rows)
})
}
Routes.put('/feedback/:id', updateAssign);

最后在邮差上发送这个PUT请求

至:http://localhost:5000/feedback/10

原料:

{
"assignee": "anna"
}

它将assignee_nickname返回为null,而不是anna:

[
{
"id": 10,
"title": "Ability to use %, em, ch, vw or similar units for dimensions.",
"description": "The title is pretty self explanatory. Very rarely (if ever) the size of components is nowadays explicitly expressed in pixels (or points), but rather it depends on the context (CSS equivalents of %, vw, vh, for example) or content (ch). It would be great if we could express units in such ways (using 1fr for stack is a nice step).n",
"created_on": "2022-08-01T20:30:21.898Z",
"category": "features",
"assignee_nickname": null
}
]

但是通过我的SQL客户端运行这个查询会返回预期的结果:

UPDATE feedback SET assignee_nickname = 'anna' WHERE id = 10

我做错了什么?

如果它在sql客户端中显示了正确的响应,那么我猜变量assignee_nickname = $1没有接收到正确的数据类型text,或者assigneeundefined您应该遵循updateAssign回调函数中的数据和console.log(assignee)。然后在这里发布回复。

最新更新