I have been trying to write some code that writes rows to my database. it:
takes an
offerobject (dependency)reads from the offer object an
itemsarray through a callback (dependency)iterates each item
takes some values from the
offeranditemobjectsreads from db some statistical data to determine the item's value
writes above two line's fields to an array
pushes the array to an array of arrays
uses this array to insert rows into db
function WriteToDB(object) {
object.getItems(function (err, items) {
var rowlist = [];
items.forEach(function (item) {
var field1 = offer.name;
var field2 = item.name;
var field3 = getItemValue(item.name); //async db call
var row = [field1, field2, field3];
rowlist.push(row);
});
write(valuelist);
}
i know this wont work, but i can't seem to grok nodejs enough to figure out how to solve this simple to be done task in other languages. I messed with learning async.waterfall, but got confused because there's a synchronous foreach loop mixed in the chain of otherwise pretty asynchronous stuff.