Sequelize批量插入数据

  • 分类:【Nodejs
  • 浏览【2016】
  • 评论【0】
  • 更新【2017-7-13 14:24:58】

sequelize提供了批量插入数据的方法:Model.bulkCreate([…object])。

User.bulkCreate([
  { username: 'barfooz', isAdmin: true },
  { username: 'foo', isAdmin: true },
  { username: 'bar', isAdmin: false }
]).then(() => { // Notice: There are no arguments here, as of right now you'll have to...
  return User.findAll();
}).then(users => {
  console.log(users) // ... in order to get the array of user objects
})

关键字词:sequelize,批量插入