通过node.js将多行插入mysql [英] insert multiple rows into mysql through node.js
本文介绍了通过node.js将多行插入mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过node.js mysql模块将多行插入mysql.我的数据是
I want to insert multiple rows into mysql thru node.js mysql module. The data I have is
var data = [{'test':'test1'},{'test':'test2'}];
我正在使用游泳池
pool.getConnection(function(err, connection) {
connection.query('INSERT INTO '+TABLE+' SET ?', data, function(err, result) {
if (err) throw err;
else {
console.log('successfully added to DB');
connection.release();
}
});
});
}
失败.
我是否可以进行批量插入并在所有插入完成后调用函数?
Is there a way for me to have a bulk insertion and call a function when all insertion finishes?
问候 锤子
推荐答案
您可以使用嵌套数组将多行插入mysql.您可以从这篇文章中看到答案:如何使用node.js在MySQL中进行批量插入
You can insert multiple rows into mysql using nested arrays. You can see the answer from this post: How do I do a bulk insert in mySQL using node.js
这篇关于通过node.js将多行插入mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文