Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const MySQL = require('mysql');
- const util = require('util');
- let config;
- try {
- config = require('../config.json');
- }
- catch(err) {
- console.log(`Config file not found, rename "config.sample.json" to "config.json"`);
- throw err;
- }
- // Setup the MySQL connection
- const pool = MySQL.createPool({
- connectionLimit: 10,
- host: config.MySQL.host,
- user: config.MySQL.user,
- password: config.MySQL.password,
- database: config.MySQL.database
- });
- // Release the connection after a query
- pool.getConnection((err, connection) => {
- if(err) console.error(err);
- if(connection) connection.release();
- return;
- });
- // Make the query return a promise
- pool.query = util.promisify(pool.query);
- /**
- * Get the current date in database format
- */
- pool.getCurrentDate = () => {
- const currentDateObj = new Date(),
- currentDate = `${currentDateObj.getUTCFullYear()}/${currentDateObj.getUTCMonth()}/${currentDateObj.getUTCDate()} ${currentDateObj.getUTCHours()}:${currentDateObj.getUTCMinutes()}:${currentDateObj.getUTCSeconds}`;
- return currentDate;
- }
- module.exports = pool;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement