从数组中创建表中的多行? [英] Create multiple rows in table from array?

查看:8
本文介绍了从数组中创建表中的多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 sequelize.js 从数组中一次添加多行?这是我的代码:

Is possible to add multiple rows at once from array with sequelize.js? This is my code:

  var user = User.build({
    email: req.body.email,
    password: req.body.password,
    userlevel: '3',
  });

  User
  .find({ where: { email: req.body.email } })
  .then(function(existingUser){

    if (existingUser) {
      return res.redirect('/staff');
    }

    user
    .save()
    .complete(function(err){
      if (err) return next(err);
      res.redirect('/staff');
    });
  }).catch(function(err){
    return next(err);
  });

感谢您的建议!

推荐答案

https://sequelize.readthedocs.io/en/v3/docs/instances/#working-in-bulk-creating-updating-and-一次销毁多行

User.bulkCreate([{ /*  record one */ }, { /* record two */ }.. ])

这篇关于从数组中创建表中的多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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