salix/services/mailer/application/database.js

34 lines
809 B
JavaScript
Raw Normal View History

2017-05-30 06:06:14 +00:00
var mysql = require('mysql');
2017-11-27 14:08:18 +00:00
let config = require('./config.js');
2017-05-30 06:06:14 +00:00
module.exports = {
2017-05-30 06:06:14 +00:00
/**
* Pool instance
2017-05-30 06:06:14 +00:00
*/
pool: null,
/**
* Start database pool
2017-05-30 06:06:14 +00:00
*/
init: function() {
2017-11-27 14:08:18 +00:00
this.pool = mysql.createPool(config.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);
2017-11-27 14:08:18 +00:00
} else if (config.app.debug) {
2017-06-07 13:28:42 +00:00
console.log('Database connection stablished');
2017-05-30 06:06:14 +00:00
}
});
},
/**
* Set test environment mail.
*/
testEmail: function() {
this.pool.query('SELECT fakeEmail as email FROM vn.config', function(error, qryRs) {
2017-11-27 14:08:18 +00:00
config.smtp.testEmail = qryRs[0].email;
});
2017-05-30 06:06:14 +00:00
}
};