Updated toothpaste

This commit is contained in:
Gitea
2019-07-19 13:56:37 +02:00
parent 20807fdacc
commit e24bdf5317
4 changed files with 52 additions and 49 deletions

View File

@@ -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;