-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
34 lines (27 loc) · 848 Bytes
/
db.js
File metadata and controls
34 lines (27 loc) · 848 Bytes
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
var mysql = require('mysql');
var fs = require('fs');
// reading connection file
var content = fs.readFileSync('./dbCredentials.json');
var credentials = JSON.parse(content);
// creating connection
var connection = mysql.createConnection(credentials);
module.exports = {
connect: function () {
connection.connect(function (err) {
if (err) {
console.error("error connection" + err.stack);
return;
}
console.log("I was able to connnect" + connection.threadId);
});
},
query: function (sql, callback) {
connection.query(sql, function (err, rows, fields) {
if (err) {
return callback(err, {}, {});
}
//connection.end();
return callback(err, rows, fields);
});
}
};