Sequelize - update record, and return result

后端 未结 7 875
粉色の甜心
粉色の甜心 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:10

    You can just find the item and update its properties and then save it. The save() results in a UPDATE query to the db

    const job = await Job.findOne({where: {id, ownerId: req.user.id}});
    if (!job) {
        throw Error(`Job not updated. id: ${id}`);
    }
    
    job.name = input.name;
    job.payload = input.payload;
    await job.save();
    

    On Postgres:

    Executing (default): UPDATE "jobs" SET "payload"=$1,"updatedAt"=$2 WHERE "id" = $3
    

提交回复
热议问题