bulkUpdate in sequelize orm

前端 未结 2 360
天涯浪人
天涯浪人 2021-01-04 07:38

How can we implement bulkUpdate like bulkCreate in sequelize orm, I searched the whole documentation of sequelize but didn\'t find anything related to bulkUpdate, so I tried

2条回答
  •  孤城傲影
    2021-01-04 07:52

    You can, if you want to update a lot of records with the same values! example: I want to update field "activationStatus" for 10 users at 1 time, 1 user = 1 record in DB and I have Array of user IDs then:

    User.update({ activationStatus: 'active'}, {
              where: {
                  id: {
                      $in: [1,2,3,4,5,6,7,8,9,10]
                  }
              }
          });
    

    it will be analogue of SQL query:

    UPDATE User SET activationStatus = 'active' WHERE id IN(1,2,3,4,5,6,7,8,9,10);
    

    you can find more info about Sequelize Operator Aliases HERE

提交回复
热议问题