Sunday, February 28, 2016

An easy-to-use MSSQL database connector for Node.js.


npm install mssql
var sql = require('mssql');
 
sql.connect("mssql://username:password@localhost/database").then(function() {
    // Query 
    
new sql.Request().query('select * from mytable').then(function(recordset) {
console.dir(recordset);
}).catch(function(err) {
// ... query error checks 
});
 
    // Stored Procedure 
new sql.Request()
.input('input_parameter', sql.Int, value)
    .output('output_parameter', sql.VarChar(50))
.execute('procedure_name').then(function(recordsets) {
console.dir(recordsets);
}).catch(function(err) {
// ... execute error checks 
});
}).catch(function(err) {
// ... connect error checks 
});
If you're on Windows Azure, add ?encrypt=true to your connection string.

No comments :

Post a Comment