How to use Tedious in Meteor

Install tedious like as per this guide.

After successfully installing tedious, as for me am using it in the Meteor.startup function my code is as below.

Meteor.startup(function() {

var Request = Npm.require(‘tedious’).Request;
var Future = Npm.require(‘fibers/future’);

var Connection = Npm.require(‘tedious’).Connection;

var config = {
userName: ‘xxxx’,
password: ‘xxxxxx’,
server: ‘xxxxxx’,
// If you’re on Windows Azure, you will need this:
options: {encrypt: true,
debug: {
packet: true,
data: true,
payload: true,
token: false,
log: true
}
}
};
fut = new Future();
var connection = new Connection(config);

connection.on(‘connect’, function(err) {

return executeStatement();
}
);

function executeStatement() {

var results = [];
request = new Request(“select * from Summary”, function(err, rowCount, rows) {

if (err) {
console.log(err);
} else {
console.log(rowCount + ‘ rows’);
fut.ret(results);

}
});
request.on(‘row’, function(columns) {
aaary = [];
cnting = 0;
columns.forEach(function(column) {
console.log(column.value);
aaary.push(column.value);
});
results.push(aaary);

});

return connection.execSql(request);

}

resulting = fut.wait();
if (!AccountSummary)
{
AccountSummary = new Meteor.Collection(‘accountsummary’);
}
AccountSummary.remove({});
resulting.forEach(function (e)

{
return AccountSummary.insert(e);
});
});

Leave a comment