[英]Sequelize - update query with returning: true succeeds but returns undefined
我有以下 function 用於將 URL 更新為用戶的個人資料圖片 -
const updateProfilePic = async (req, res) => {
const userId = req.param("id");
if (userId) {
const targetPath = `...`;
User.update(
{
profilePic: targetPath
},
{ where: { id: userId }, returning: true }
)
.then(updatedUser => {
console.log(updatedUser);
res.json(updatedUser);
})
.catch(error => {
console.log(error);
res.status(400).send({ error: error });
});
}
};
這成功更新了數據庫 - 但是then
獲得[ undefined, 1 ]
作為updatedUser
而不是用戶數據 - 如果我刪除returning: true
標志,它只會返回[ 1 ]
。 我不確定我做錯了什么 - 我正在嘗試獲取用戶 object 以便我可以將其傳遞給客戶端。
我想你沒有使用 Postgres。
options 中的returning
屬性僅在 Postgres 中受支持。
Update()
返回一個包含一個或兩個元素的數組。 第一個元素是受影響的行數。 第二個數組元素僅在 postgres 中受支持,並將返回更新的行。
所以你得到1返回,它是更新的行數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.