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