mysql-apm.js
792 Bytes
'use strict';
const mysql = require('promise-mysql');
const config = require('../config/config');
const mysqlPool = mysql.createPool({
host: config.apmMysql.host,
user: config.apmMysql.user,
password: config.apmMysql.password,
port: config.apmMysql.port,
database: config.apmMysql.database
});
class MysqlPromise {
constructor() {
this.mysql = mysqlPool;
}
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;