2017-05-30 06:06:14 +00:00
|
|
|
var mysql = require('mysql');
|
2017-08-30 12:10:43 +00:00
|
|
|
let settings = require('./settings.js');
|
2017-05-30 06:06:14 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2017-05-30 06:06:14 +00:00
|
|
|
/**
|
2017-08-30 12:50:46 +00:00
|
|
|
* Pool instance
|
2017-05-30 06:06:14 +00:00
|
|
|
*/
|
|
|
|
pool: null,
|
|
|
|
|
|
|
|
/**
|
2017-08-30 12:50:46 +00:00
|
|
|
* Start database pool
|
2017-05-30 06:06:14 +00:00
|
|
|
*/
|
|
|
|
init: function() {
|
2017-05-31 11:46:18 +00:00
|
|
|
this.pool = mysql.createPool(settings.mysql());
|
2017-05-30 06:06:14 +00:00
|
|
|
|
|
|
|
this.pool.getConnection(function(error, connection) {
|
|
|
|
if (error) {
|
2017-06-07 13:28:42 +00:00
|
|
|
throw new Error('Can\'t connect to database: ' + error.code);
|
|
|
|
} else if (settings.app().debug) {
|
|
|
|
console.log('Database connection stablished');
|
2017-05-30 06:06:14 +00:00
|
|
|
}
|
|
|
|
});
|
2017-08-30 12:10:43 +00:00
|
|
|
},
|
2017-08-30 12:50:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set test environment mail.
|
|
|
|
*/
|
2017-08-30 12:10:43 +00:00
|
|
|
testEmail: function() {
|
|
|
|
this.pool.query('SELECT fakeEmail as email FROM vn.config', function(error, qryRs) {
|
|
|
|
settings.testEmail = qryRs[0].email;
|
|
|
|
});
|
2017-05-30 06:06:14 +00:00
|
|
|
}
|
|
|
|
};
|