// .limit() paginates Array by 50 items
some_array.limit(50, function(items, next) {
var sql = DB();
var builder = [];
// Creates raw SQL queries
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
builder.push('INSERT INTO tbl_products (id, name, price) VALUES({0},{1},{2})'.format(sql.escape(item.id), sql.escape(item.name), sql.escape(item.price)));
}
// Runs one big query
sql.query(builder.join('\n'));
sql.exec(function(err) {
err && console.error(err);
// Process next 50 pieces
next();
});
}, () => console.log('DONE'));