node.js - Sequelize bulkCreate from JSON File -
i create json file records insert , use model.bulkcreate insert records @ once when read file "typeerror: records.map not function"
database.js
fs.readfile(__dirname + "/databasetables/consoleandplatform.json", function(err, data){ consoleandplatform.bulkcreate(data.tostring()) })
consoleandplatform.json
[{console: "xbox", platform: "xbox 360", name: "xbox 360"},{ console: "xbox", platform: "xbox one", name: "xbox one"},{ console: "xbox", platform: "xbox live", name: "xbox live"},{ console: "ps", platform: "ps4", name: "playstation 4"}]
thanks help
ok found solution maybe helpful someone. first of json wrong, should be:
[ { "console": "xbox", "platform": "xbox 360", "name": "xbox 360" }, { "console": "xbox", "platform": "xbox one", "name": "xbox one" }, { "console": "xbox", "platform": "xbox live", "name": "xbox live" }]
and second need json.parse string result:
consoleandplatform.bulkcreate(json.parse(data.tostring()))
Comments
Post a Comment