如何在MySQL中插入多个logging/行
在Sails.js中可以插入多个logging吗? 我正在使用MySQL,我需要根据来自API的请求将“n”行保存到MySQL中。
我需要关于Sails.js的帮助谢谢
是的,你可以一次写入多个logging在MySQL中。 让我的模型是:
module.exports = { tableName:'test', autoCreatedAt:false, autoUpdatedAt:false, attributes: { name:'string' } };
首先让我们看看在mysql查询中是如何完成的。
INSERT INTO `test` VALUES (1,'AB'),(2,'ABCCDC');
现在这是如何添加多个logging…
Test.create([{name:'name1'},{name:'name2'},{name:'name3'}]) .exec(function(err,done){ if(err){ //hendle the error; return; } //successfully inserted; });
现在我想我的观点很清楚。
你只需要传递
array of objects in model.create()
来插入多个对象。