The task is to get parts of data from the columns object and send it to the database. The parts must have the maximum size of insertMaxRows.
I tried some iterations and using the modulo operator. However I am still a beginner, can't get my head around this problem.
var insertMaxRows = utils.GetInsertMaxRows(); //right now its 2
var idx = 1;
for (var i = 0; i < columns.id.length; i++) {
if (idx % insertMaxRows == 0){
var params = [];
//this takes just 1 value, i know
params.push(columns.codes[idx -1]);
params.push(columns.product_id[idx -1]);
params.push(columns.id[idx -1]);
updateSql = "UPDATE TProductCodes SET code =?, product_id =? WHERE id =?";
sql.query(connection, params, etc, callback) {
//sends stuff to database
});
idx++;
}
When insertMaxRows
is 2
, for example, this code should send the first 2 items in the arrays to the database, then the next 2, and so on, then the rest is there is any.
Please note that this is for NODE JS and will be sent to the database in a asynchronous function, if it matters at all.