-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
41 lines (35 loc) · 1.03 KB
/
database.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
'use strict';
var mysql = require('mysql')
var databaseConfig = {
user: 'tparty',
password: 'Test1234!',
host: 'den1.mysql6.gear.host',
database: 'tparty'
};
module.exports = {
init: function (next) {
var sqlConnection = mysql.createConnection(databaseConfig)
sqlConnection.connect(function (err) {
if (err) {
console.error('Error connecting ' + err.stack);
setTimeout(init((err, val) => { }), 2000);
}
else
next(null, sqlConnection);
});
sqlConnection.on('error', function (err) {
if (err.code == 'PROTOCOL_CONNECTION_LOST') {
init((err, val) => { });
}
else
next(err)
})
},
query: function (sqlConnection, sqlQuery, next) {
sqlConnection.query(sqlQuery, function (error, rows) {
if (error)
next(error)
next(null, rows)
});
}
}