Advertisement
Guest User

Untitled

a guest
Apr 1st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. const mysql = require('mysql');
  2.  
  3.  
  4. class MysqlPool {
  5.  
  6. credentials = {};
  7. pool;
  8.  
  9. constructor(host, user, password, database) {
  10.  
  11. this.credentials.host = host;
  12. this.credentials.user = user;
  13. this.credentials.password = password;
  14. this.credentials.database = database;
  15.  
  16. this.pool = mysql.createPool(this.credentials);
  17. }
  18.  
  19. async query(query, placeholders) {
  20.  
  21. return new Promise((resolve, reject) => {
  22.  
  23. this.pool.getConnection(function(err, connection) {
  24.  
  25. connection.query(query, placeholders, function (error, result, fields) {
  26.  
  27. connection.release();
  28.  
  29. if (error) {
  30. return reject(error);
  31. }
  32.  
  33. resolve(result);
  34.  
  35. });
  36.  
  37. });
  38.  
  39. });
  40.  
  41. }
  42.  
  43. }
  44.  
  45. module.exports = MysqlPool;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement