Updated toothpaste
This commit is contained in:
55
js/mysql.js
55
js/mysql.js
@@ -1,26 +1,53 @@
|
||||
var mysql = require('mysql');
|
||||
var fs = require("fs");
|
||||
var mysql = require('mysql');
|
||||
var fs = require("fs");
|
||||
|
||||
var file = null;
|
||||
var connection = null;
|
||||
var file = null;
|
||||
var connectionConfig;
|
||||
var connection = null;
|
||||
|
||||
function handleDisconnect() {
|
||||
connection = mysql.createConnection(connectionConfig);
|
||||
|
||||
connection.connect(function(err) {
|
||||
if(err) {
|
||||
console.log('error when connecting to db:', err);
|
||||
setTimeout(handleDisconnect, 2000);
|
||||
}
|
||||
else {
|
||||
console.log("Connected to MySQL database ( "+connectionConfig.user+"@"+connectionConfig.host+"/"+connectionConfig.database+" )");
|
||||
}
|
||||
});
|
||||
connection.on('error', function(err) {
|
||||
console.log('db error', err);
|
||||
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
|
||||
handleDisconnect();
|
||||
} else if(err.code === 'ECONNRESET'){
|
||||
handleDisconnect();
|
||||
} else{
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
file = fs.readFileSync("./config.json");
|
||||
file = fs.readFileSync("./config.json");
|
||||
}
|
||||
catch(exception) {
|
||||
console.log(exception.toString());
|
||||
console.log(exception.toString());
|
||||
}
|
||||
|
||||
if(file != null) {
|
||||
var json = JSON.parse(file);
|
||||
var json = JSON.parse(file);
|
||||
|
||||
connection = mysql.createConnection({
|
||||
host: json.host,
|
||||
database: json.database,
|
||||
user: json.user,
|
||||
password: json.password
|
||||
});
|
||||
connectionConfig = {
|
||||
host: json.host,
|
||||
database: json.database,
|
||||
user: json.user,
|
||||
password: json.password
|
||||
};
|
||||
|
||||
handleDisconnect();
|
||||
}
|
||||
|
||||
|
||||
module.exports = connection;
|
||||
module.exports = connection;
|
||||
|
||||
Reference in New Issue
Block a user