簡體   English   中英

使用 Sequelize 為請求 Node.Js 中給出的現有字段更新數據庫

[英]Update database using Sequelize for existing field given in request Node.Js

如何僅為客戶提供給我們 API 的現有字段更新我們的 model?

例子:

User.update({‘name’: ‘value_1’, {‘email’: ‘value_2’,}.then().catch()

I want to automatically update my User model based on what my client give when Requesting my API (if they only provide name , then my Model only update the name field without updating the email field). 有沒有這樣做的最佳實踐?

您可以獲取正在使用的用戶,分配接收到的參數並保存用戶

例如:

const user = await User.findByPk(id);
Object.assign(user, params);
await user.save();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM