此代码需要循环遍历数组中的 1050 个项目,并填充 postgres 数据库中的产品表。不幸的是,它停在 1000 处,没有错误。有谁知道为什么会发生这种情况?
import data from './data';
const Sequelize = require('sequelize');
const sequelize = new Sequelize('graphql', 'billy', '', {
host: 'localhost',
dialect: 'postgres',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
const Data = sequelize.define('data', {
name: Sequelize.TEXT,
});
// force: true will drop the table if it already exists
Data.sync({ force: true })
.then(() => {
return data.map(d => {
return Data.create({
name: d.name,
});
});
});
最佳答案
您可以使用Model.bulkCreate
函数代替Model.create
Data.sync({force: true})
.then(() => {
const dataList = data.map( d => { name: d.name});
return Data.bulKCreate(dataList).then( result => result);
});
关于javascript - SequelizeJS 映射在第 1000 个循环处停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50330990/