NodeJS 使用 Sequelize 和块数据批量插入 MySQL
我想用semelize orm和nodejs(Nestjs)插入MySQL。我很好奇是否有一个处理非常大数据的最佳方法。我想到了拉拉维尔(Laravel)的“块”。在Laravel中,我们可以这样做:
$chunks = $insert_data->chunk(500);
foreach ($chunks as $chunk) {
\DB::table('items_details')->insert($chunk->toArray());
}
是否有人使用semelize和nodejs实现了此操作。谢谢
I want to bulk insert MySQL with Sequelize ORM and NodeJS (NestJS). I'm curious if there is a best way to handle very large data. I thought of "chunk" like Laravel did. In Laravel we can do it like this:
$chunks = $insert_data->chunk(500);
foreach ($chunks as $chunk) {
\DB::table('items_details')->insert($chunk->toArray());
}
Has anyone implemented this with sequelize and NodeJS. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想它几乎是一样的(使用 lodash 来获取块):
PS 根据您想要实现的目标,您可以使用事务来插入所有块,或者如果出现错误则不插入任何块插入任何块时或使用
try/catch
绕过或在失败后继续插入其他块。I suppose it would be almost the same (using
lodash
to get chunks):P.S. Depending on what you want to achieve you either use a transaction to insert all chunks or none of them if there will is an error while inserting any of chunks OR use
try/catch
to bypass or continue inserting other chunks after failed one.