是否可以使用 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 */ }.. ])
这篇关于从数组中创建表中的多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!