从数组中创建表中的多行?
是否可以使用 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 */ }.. ])
相关文章