forked from twright-msft/mssql-node-docker-demo-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (43 loc) · 1.36 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var express = require("express");
var app = express();
var connection = require('tedious').Connection;
var request = require('tedious').Request;
app.get('/', function (req, res) {
//set up the connection information
var config = {
server: 'localhost',
authentication: {
type: 'default',
options: {
userName: 'sa',
password: 'Yukon900', // update me
database: 'DemoData' // doesn't seem to work?
},
}
};
var conn = new connection(config);
conn.on('connect', function(err) {
if (err) {
console.log(err);
} else {
sqlreq = new request("SELECT * FROM DemoData.dbo.Products FOR JSON AUTO", function(err, rowCount) {
if (err) {
console.log(err);
}
});
sqlreq.on('row', function(columns) {
columns.forEach(function(column) {
if (column.value === null) {
console.log('NULL');
} else {
res.send(column.value);
}
});
});
conn.execSql(sqlreq);
}
});
})
var server = app.listen(8080, function () {
console.log("Listening on port %s...", server.address().port);
});