mysql-apm.js 809 Bytes
'use strict';

const mysql = require('promise-mysql');
const config = require('../config/config');

class MysqlPromise {
    constructor() {
        this.mysql = mysql.createPool({
            host: config.apmMysql.host,
            user: config.apmMysql.user,
            password: config.apmMysql.password,
            port: config.apmMysql.port,
            database: config.apmMysql.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;