Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mysql = require('whatever-mysql-lib');
  2.  
  3. let pool = null;
  4.  
  5. const getConnection() {
  6.     if (pool === null) {
  7.         pool = mysql.createPool({
  8.             connectionLimit: 10,
  9.             host: 'localhost',
  10.             user: 'root',
  11.             password: '<snip>',
  12.             database: 'purchases'
  13.         });    
  14.     }
  15.     return pool.getConnection();
  16. };
  17.  
  18. const query(query) {
  19.     let connection = getConnection();
  20.     return connection.query(query);
  21. }
  22.  
  23. module.exports = {
  24.     query: query,
  25.     getConnection: getConnection
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement