-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (49 loc) · 1.85 KB
/
index.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
52
53
54
var http = require('http')
var port = process.env.port || 1337;
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
var getRow = "SELECT Description,Priority,Status from Tasks;"
var insertRow = "INSERT INTO Tasks (Description,Priority,Status)VALUES ('Sleep','High','Pending');"
var updateRow = "UPDATE Tasks SET Priority='Low' WHERE Status='new';"
var deleteRow = "DELETE FROM Tasks where Status = 'done';";
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
var Connection = require('tedious').Connection;
var config = {
userName: 'sysgain',
password: 'ThisIsPassword@123',
server: 'p868gm7zdb.database.windows.net',
// If you are on Microsoft Azure, you need this:
options: {encrypt: true, database: 'myDB'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
// If no error, then good to proceed.
console.log("Connected");
executeStatement(deleteRow);
});
function executeStatement(query) {
request = new Request(query , function(err) {
if (err) {
console.log(err);}
});
var result = "";
request.on('row', function(columns) {
columns.forEach(function(column) {
if (column.value === null) {
console.log('NULL');
} else {
result+= column.value + " ";
}
});
console.log(result);
result ="";
});
request.on('done', function(rowCount, more) {
console.log(rowCount + ' rows returned');
});
connection.execSql(request);
console.log('All Done');
}