使用nodejs SQL DB2插入大量数据

我得到可以说数组100.000logging:

var eData = { "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" }, { "id": "1003", "type": "Blueberry" }, { "id": "1004", "type": "Devil's Food" } 

等等…当我发射下面的node.js脚本

 var db = require('/QOpenSys/QIBM/ProdData/OPS/Node6/os400/db2i/lib/db2a'); var DBname = "*LOCAL"; var dbconn = new db.dbconn(); dbconn.conn(DBname); var sqlA = new db.dbstmt(dbconn); eData.forEach(function(eRow, i) { var sql = "INSERT INTO lib.table VALUES( xx xxx) WITH NONE" sqlA.exec(sql, function(rs, err) { console.log("Execute Done."); console.log(err); }); }); 

数据将在数据库中混合。 相同的ID和types将在那里10次,但它会达到插入logging的确切数量。

如果我更改为execSync,一切正常,但接缝有点慢。 我错过了做什么asynchronous插入?

什么是做巨大的插入最快的方式?

将有最佳数量的asynchronous操作在任何时候进行处理。 限制asynchronous操作​​的最简单方法是使用优秀的async.js模块。

https://caolan.github.io/async/docs.html#eachLimit

 var async = require('async') var db = require('/QOpenSys/QIBM/ProdData/OPS/Node6/os400/db2i/lib/db2a'); var DBname = "*LOCAL"; var dbconn = new db.dbconn(); dbconn.conn(DBname); var sqlA = new db.dbstmt(dbconn); async.eachLimit(eData, 100, function(eRow, cb) { var sql = "INSERT INTO lib.table VALUES( xx xxx) WITH NONE" sqlA.exec(sql, function(rs, err) { console.log("Execute Done."); cb(err) }); }, function (error) { if (error) { console.error(error) } else { console.log('Done') } })