如何将数组或json插入表中? array或json包含所有字段和值。
{
"userId":24,
"addressList":[{ "city":"delhi",
"state":"delhi"
},
{ "city":"gurugram",
"state":"hariyana"
},
{ "city":"dehradun",
"state":"uttrakhand"
}]
}
表详情: userId城市州 24德里德里 24 Gurugram Hariyana 24 Dehradun uttrakhand
答案 0 :(得分:0)
在续集中使用bulkCreate()
函数。
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
})
这是一个示例示例。 Refer to this for bulk create docs