使用Node和mssql进行流式处理

时间:2016-06-19 04:27:13

标签: sql-server node.js express pug

我搜索了很多但是找不到使用mssql中的节点来获取Node的实例

数据控制器

//Data controller used to query and update the database
var sql = require('mssql');

//Config data for database connection
var config = {
    user: '',
    password: '',
    server: '',
    stream: true,
    database: ''
};  

module.exports.queryDatabase = function(req, res, sqlQueryString) {
    var contactList = [];
    var connection = new sql.Connection(config, function(err) {
        if(err) {
            console.log(err)
        } else {
            var request = new sql.Request(connection);
            request.query(sqlQueryString);
            request.on('row', function(row) {
            });
    connection.close();
        }
    });
};

页面渲染控制器:

var data = require(./data);
    module.exports.renderInvestorsPage = function(req, res) {
    buildQuery = 'SELECT contact_info.last_name, \
                  contact_info.first_name, \
                  contact_info.contact_key, \
                  contact_info.work, \
                  contact_info.home, \
                  contact_info.email \
                  FROM contact_info \
                  WHERE contact_info.investor = 1';
    investorResults = data.queryDatabase(req, res, buildQuery);
    console.log(investorResults);
    res.render('investors', {title: 'Investors'});
};

查看:

extends layout

block content
    div.row
        div.col-lg-12
        h1.page-header #{title}
    div.row
        table
            tr
                th Last Name
                th First Name
                th Work Phone
                th Home Phone
                th Email
            tbody
                each investor in investorResults
                    td= investor.last_name
                    td= investor.first_name
                    td= investor.work
                    td= investor.home
                    td= investor.email

我很难过为什么我不能以这种方式使用查询结果。似乎问题必须是使用mssql的流媒体选项,但不情愿我必须使用流,因为我正在使用10,000个联系人...

0 个答案:

没有答案