code: function(params, cb, oldscope) {
  		query.params = params;
  		// Note the callback function has the data and error reversed due to existing code in promiseExec which has the
  		// err and data swapped.  This trickles down into alasql.exec and further. Rather than risk breaking the whole thing,
  		// the (data, err) standard is maintained here.
  		var res1 = queryfn(query, oldscope, function(res, err) {
  			if (err) {
  				return cb(err, null);
  			}
  			if (query.rownums.length > 0) {
  				for (var i = 0, ilen = res.length; i < ilen; i++) {
  					for (var j = 0, jlen = query.rownums.length; j < jlen; j++) {
  						res[i][query.rownums[j]] = i + 1;
  					}
  				}
  			}
  
  			var res2 = modify(query, res);
  
  			if (cb) {
  				cb(res2);
  			}
  			//console.log(8888,res2);
  			return res2;
  		});
  		//console.log(9999,res1);
  
  		//		if(typeof res1 != 'undefined') res1 =  modify(query,res1);
  
  		return res1;
  	}
docs: console.log(query); Now, compile all togeather into one function with query object in scope