I am parsing an excel file, that has 7 columns and over 300k rows.
I need to create objects (Nodejs side) and make a bulk insert in the database.
I am wondering what would be the best way to create large amounts of objects for this purpose.
I have come up with three approaches, and not sure which one would be the nest in terms of speed and memory:
First:
var bulkObjects = [];
worksheet.eachRow({includeEmpty: true}, function (row, rowNumber) {
var currentObject = createRowObject(row.values);
bulkObjects.push(currentObject);
});
function createRowObject(row) {
return {
Row1: row[1],
Row2: row[2],
Row3: row[3],
Row4: row[4],
Row5: row[5],
Row6: row[6]
}
}
Second:
var bulkObjects = [];
worksheet.eachRow({includeEmpty: true}, function (row, rowNumber) {
var currentObject = **new** createRowObject(row.values);
bulkObjects.push(currentObject);
});
function createRowObject(row) {
this.Row1: row[1],
this.Row2: row[2],
this.Row3: row[3],
this.Row4: row[4],
this.Row5: row[5],
this.Row6: row[6]
}
Third:
var bulkObjects = [];
worksheet.eachRow({includeEmpty: true}, function (row, rowNumber) {
var currentObject = createRowObject(row.values);
bulkObjects.push(currentObject);
});
function createRowObject(row) {
var o = new Object();
o["Row1"] = row[1];
o["Row2"] = row[2];
o["Row3"] = row[3];
o["Row4"] = row[4];
o["Row5"] = row[5];
o["Row6"] = row[6];
return o;
}
Which one would be the best to create large amount of objects. Is there a another approach?