Authored by 郝肖肖

'mysql-lib'

... ... @@ -18,6 +18,13 @@ const defaults = {
port: '6379',
//password: ''
}
},
mysql: {
host: '192.168.102.219',
user: 'yh_test',
password: 'yh_test',
port: '3306',
database: 'seo',
}
};
... ...
'use strict';
const mysql = require('promise-mysql');
const config = require('../config/config');
class MysqlPromise {
constructor() {
this.connect().then(conn => {
this.connect = conn;
});
}
connect() {
if (this.connect) {
return Promise.resolve(this.connect);
}
return mysql.createConnection({
host: config.mysql.host,
user: config.mysql.user,
password: config.mysql.password,
port: config.mysql.port,
database: config.mysql.database
}).then(conn => {
return conn;
}).catch(err => {
console.error(`mysql connect fail, err: ${err.message}`);
return null;
});
}
}
module.exports = MysqlPromise;
\ No newline at end of file
... ...
... ... @@ -54,6 +54,7 @@
"node-zookeeper-client": "^0.2.2",
"nodemailer": "^3.1.8",
"npm": "^3.10.9",
"promise-mysql": "^3.0.1",
"qcloudapi-sdk": "^0.1.5",
"qn": "^1.3.0",
"qs": "^6.2.0",
... ... @@ -68,4 +69,4 @@
"devDependencies": {
"nodemon": "^1.11.0"
}
}
\ No newline at end of file
}
... ...