2014-05-08 25 views
-2

我正在使用此模塊tedious進行連接。我嘗試使用MSSQL中的數據填充集合時遇到問題。如何在流星中製作繁瑣的異步

我的代碼迄今:

http://pastebin.com/q4ByRCbW

Meteor.startup(function() { 

    var Request = Meteor.require('tedious').Request; 
    var Connection = Meteor.require('tedious').Connection; 

    var config = { 
     userName: 'xxxxx', 
     password: 'xxxx', 
     server: '197.xxx.xxx.xxx', 

     // If you're on Windows Azure, you will need this: 
     options: { 
      encrypt: true, 
      debug: { 
       packet: true, 
       data: true, 
       payload: true, 
       token: false, 
       log: true 
      } 
     } 
    }; 

    var connection = new Connection(config); 
    var asnycWrapFunc = Async.wrap(connection.execSql); 
    var rettarr = []; 

    function executeStatement() { 
     Fiber(function(){ 
      request = new Request("select * from AccountSummary", function(err, rowCount) { 
       if (err) { 
       console.log(err); 
       } else { 
       console.log(rowCount + ' rows'); 
       } 
      }); 
     request.on('row', function(columns) { 
      aaary = []; cnting = 0; 
      columns.forEach(function(column) { 
       console.log(column.value); 
       aaary.push(column.value); 
      }); 
      if (AccountSummary.find().count() === 0){ 
       AccountSummary.insert({ID:aaary[0], ClientNo:aaary[1], ClientName:aaary[2]}); 
      } 

     }); 
     //rettarr.push(aaary); 
     }).run(); 

     asnycWrapFunc(request); 
     //return rettarr; 
    } 

    connection.on('connect', function(err) { 
     // If no error, then good to go... 
      var res = executeStatement(); 
      // aaary = res[0]; 

      console.log(res); 
      errr = err; 
    }); 
}); 
+1

什麼樣的問題?問題是什麼?請在此發佈相關代碼部分,說明您期望實現的目標以及獲得的內容。 –

+0

歡迎來到SO。請不要依靠外部網站來託管您的代碼,而是在您的問題中包含相關部分。而且它仍然缺少您所擁有的問題,編輯您的問題以添加細節並使其儘可能清晰。 – nikoshr

+0

我將代碼粘貼到pastebin中。 http://pastebin.com/q4ByRCbW。我遇到的錯誤範圍從光纖未定義到流星代碼必須始終在光纖內運行。我只是想讓別人知道如何在流星中正確包裝單調乏味的函數,這樣我就會得到這些錯誤 – user1863492

回答