Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. const MySQL = require('mysql');
  2. const util = require('util');
  3.  
  4. let config;
  5.  
  6. try {
  7. config = require('../config.json');
  8. }
  9. catch(err) {
  10. console.log(`Config file not found, rename "config.sample.json" to "config.json"`);
  11. throw err;
  12. }
  13.  
  14. // Setup the MySQL connection
  15. const pool = MySQL.createPool({
  16. connectionLimit: 10,
  17. host: config.MySQL.host,
  18. user: config.MySQL.user,
  19. password: config.MySQL.password,
  20. database: config.MySQL.database
  21. });
  22.  
  23. // Release the connection after a query
  24. pool.getConnection((err, connection) => {
  25. if(err) console.error(err);
  26.  
  27. if(connection) connection.release();
  28.  
  29. return;
  30. });
  31.  
  32. // Make the query return a promise
  33. pool.query = util.promisify(pool.query);
  34.  
  35. /**
  36. * Get the current date in database format
  37. */
  38. pool.getCurrentDate = () => {
  39. const currentDateObj = new Date(),
  40. currentDate = `${currentDateObj.getUTCFullYear()}/${currentDateObj.getUTCMonth()}/${currentDateObj.getUTCDate()} ${currentDateObj.getUTCHours()}:${currentDateObj.getUTCMinutes()}:${currentDateObj.getUTCSeconds}`;
  41.  
  42. return currentDate;
  43. }
  44.  
  45. module.exports = pool;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement