【发布时间】:2020-04-12 03:20:52
【问题描述】:
我正在制作我的第一个带有 react 的 postgres 应用程序。这是一个简单的待办事项列表。
现在,当您检索任务列表时,您会得到以下信息:
pernstack=# SELECT * FROM todo;
todo_id | description
---------+-------------------------------
825 | First task
826 | Second Task
824 | Third task
822 | Fourth task
(4 rows)
问题是如果我使用PUT 请求编辑第一个任务。该任务被放在列表的底部。这是编辑请求:
app.put("/todos/:id", async (req, res) => {
try {
const { id } = req.params;
const { description } = req.body;
const updateTodo = await pool.query(
"UPDATE todo SET description = $1 WHERE todo_id = $2",
[description, id]
);
res.json("Todo was updated");
} catch (err) {
console.error(err.message);
}
});
在不乱序的情况下编辑任务的最基本方法是什么?我不想手动添加index 列。在 MySQL 中,我相信这是自动完成的。
【问题讨论】:
标签: node.js postgresql express