-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.js
51 lines (40 loc) · 1.3 KB
/
run.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
50
51
var mssql = require('mssql');
console.log('Running SQL Query');
mssql.connect(process.env['SQLAZURECONNSTR_SQLDB'], function(err) {
// ... error checks
if(err) {
console.log('Connection broke');
return console.log(err);
}
var request = new mssql.Request();
request.stream = true; // You can set streaming differently for each request
request.query("select 'foobar' as result"); // or request.execute(procedure);
request.on('recordset', function(columns) {
// Emitted once for each recordset in a query
});
request.on('row', function(row) {
// Emitted for each row in a recordset
console.log(row);
});
request.on('error', function(err) {
// May be emitted multiple times
console.log('Query broke');
console.log(err);
});
request.on('done', function(returnValue) {
// Always emitted as the last one
console.log('Completed Query');
process.exit(0);
});
});
mssql.on('error', function(err) {
// ... error handler
console.log('Could not connect to SQL DB');
process.exit(1);
});
process.on('uncaughtException', function(err) {
console.log('Unhandled Exception', err);
});
process.on('exit', function(code) {
console.log('About to exit with code:', code);
});