【问题标题】:How to make tedious Async in Meteor如何在 Meteor 中进行繁琐的异步操作
【发布时间】:2014-06-25 15:58:05
【问题描述】:

我正在使用此模块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;
    });
});

【问题讨论】:

  • 什么样的问题?问题是什么?请在此处发布代码的相关部分,说明您期望实现的目标和获得的结果。
  • 欢迎来到 SO。请不要依赖外部网站来托管您的代码,而是在您的问题中包含相关部分。它仍然缺少您遇到的问题,请编辑您的问题以添加详细信息并使其尽可能清晰。
  • 我将代码粘贴到了 pastebin 中。 pastebin.com/q4ByRCbW。我收到了从未定义的 Fiber 到 Meteor 代码必须始终在 Fiber 中运行的错误。我只是想让有人告诉我如何在流星中正确包装繁琐的函数,这样我就会得到这些错误

标签: node.js mongodb meteor node-fibers tedious


【解决方案1】:

我发现如果你想给你一个像 Tedious 这样的包,你必须使用 Future。

This mini tutorial has the answer

【讨论】:

    猜你喜欢
    • 2019-02-28
    • 1970-01-01
    • 2019-12-28
    • 2017-09-09
    • 2023-03-16
    • 2016-12-20
    • 2022-10-01
    • 2014-04-10
    • 1970-01-01
    相关资源
    最近更新 更多