34 lines
809 B
JavaScript
34 lines
809 B
JavaScript
var mysql = require('mysql');
|
|
let config = require('./config.js');
|
|
|
|
module.exports = {
|
|
/**
|
|
* Pool instance
|
|
*/
|
|
pool: null,
|
|
|
|
/**
|
|
* Start database pool
|
|
*/
|
|
init: function() {
|
|
this.pool = mysql.createPool(config.mysql);
|
|
|
|
this.pool.getConnection(function(error, connection) {
|
|
if (error) {
|
|
throw new Error('Can\'t connect to database: ' + error.code);
|
|
} else if (config.app.debug) {
|
|
console.log('Database connection stablished');
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Set test environment mail.
|
|
*/
|
|
testEmail: function() {
|
|
this.pool.query('SELECT fakeEmail as email FROM vn.config', function(error, qryRs) {
|
|
config.smtp.testEmail = qryRs[0].email;
|
|
});
|
|
}
|
|
};
|