Monday, 28 May 2018

Need Help with 'mssql' Module

It's my first time working with anything Javascript related.I have a DB table formatted as such:KeyID | TableID | ColumnName | ColumnValue | ColumnType which is a sort of pivoted info table for storing a backup (baseline) of data from other tables.In my node app, I havean array of tables to be baselined (var tables = [])an array of keyIDs to use (table[i].Keys = []an array of the expected columns from destination table (table[i].Columns = [])I was trying to keep it simple, planning on just going table-by-table, running one keyId at a time on each table.async function(table) =>{ for(key in table.Keys){ p1.prepare(SELECT * FROM dbo.BackUpTable WHERE TableName = @tableName AND KeyId = @keyId) .then(() => { await p1.execute(tableName:table,keyId:key) .then(() => { then await formatting the record into an object array like:/* [ {ColName: 'blahblah', ColVal: 'blahblahval', ColType:'type'}, {ColName: 'blahblah2', ColVal:'blahblah2val', ColType:'type'} . . . ] */ Then await inserting into the destination tableawait p2.prepare("INSERT INTO @destTable (@cols) VALUES (@vals)") await p2.execute(/*stuff*/) })//end the execute.then() statement })//end the prepare.then() statement }//end for loop }//end function but this is clearly a bad way to do it, because I'm getting lost in all the nested "async await" to make it not run all 4000 key requests asynchronously or end up moving ahead before getting all the data formatted or whatever.I'm stuck thinking slowly and synchronously. How should I approach this problem instead?

Submitted May 28, 2018 at 08:40PM by I_HAVE_THAT_FETISH

No comments:

Post a Comment