Sequelize - update record, and return result

后端 未结 7 843
粉色の甜心
粉色の甜心 2020-12-28 11:20

I am using sequelize with MySQL. For example if I do:

models.People.update({OwnerId: peopleInfo.newuser},
        {where: {id: peopleInfo.scenario.id}})
             


        
相关标签:
7条回答
  • 2020-12-28 12:19

    If you're using postgres and updating one row.

      try {
        const result = await MODELNAME.update(req.body, {
          where: { id: req.params.id },
          returning: true
        });
        if (!result) HANDLEERROR()
        const data = result[1][0].get();
    
        res.status(200).json({ success: true, data });
      } catch (error) {
        HANDLEERROR()
      }
    
    0 讨论(0)
提交回复
热议问题