'use strict'; const mysql = require('promise-mysql'); const config = require('../config/config'); class MysqlPromise { constructor() { this.mysql = mysql.createPool({ host: config.mysql.host, user: config.mysql.user, password: config.mysql.password, port: config.mysql.port, database: config.mysql.database }); } query(sql, values) { return this.mysql.getConnection().then(conn => { return conn.query(sql, values).then(d => { this.mysql.releaseConnection(conn); return d; }); }).catch(err => { console.error(`mysql query, err: ${err.message}`); return []; }); } } module.exports = MysqlPromise;