sequelize orm 中的 bulkUpdate [英] bulkUpdate in sequelize orm

查看:24
本文介绍了sequelize orm 中的 bulkUpdate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在sequelize orm中实现bulkUpdate,如bulkCreate,我搜索了 sequelize 的整个文档,但没有找到与 bulkUpdate 相关的任何内容,所以我尝试在for循环中循环更新,它可以工作,但是还有其他方法可以批量更新

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 to loop update in for loop, it works but is there any other way to update in bulk

推荐答案

使用 bulkCreate 到 bulkUpdate 方法.

Use the bulkCreate to bulkUpdate method.

bulkCreate([...], { updateOnDuplicate: ["name"] })

updateOnDuplicate 是一个字段数组,当主键(或可能是唯一键)匹配行时将更新这些字段.确保您的模型和 dataArray 中至少有一个唯一字段(比如说 id)用于 upsert.

updateOnDuplicate is an array of fields that will be updated when the primary key (or may be unique key) match the row. Make sure you have at least one unique field (let say id) in your model and in the dataArray both for upsert.

供参考参考这里

这篇关于sequelize orm 中的 bulkUpdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆