25 lines
566 B
JavaScript
25 lines
566 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');
|
|
}
|
|
});
|
|
}
|
|
};
|