parent
2b0c88fd66
commit
21053fd3bf
|
@ -1,3 +1,8 @@
|
|||
2.2.0 / 2018-03-15
|
||||
==================
|
||||
* 连接池增加失败移除配置和恢复时间
|
||||
|
||||
|
||||
2.1.3 / 2018-03-14
|
||||
==================
|
||||
* 优化异常输出
|
||||
|
|
5
index.js
5
index.js
|
@ -30,7 +30,10 @@ class Mysqli {
|
|||
|
||||
//是否有从库
|
||||
this.useSlaveDB = config.length > 1
|
||||
this.pool = mysql.createPoolCluster()
|
||||
this.pool = mysql.createPoolCluster({
|
||||
removeNodeErrorCount: 1, // 连续失败立即从节点中移除, 并在10秒后尝试恢复
|
||||
restoreNodeTimeout: 10000
|
||||
})
|
||||
|
||||
config.forEach((item, i) => {
|
||||
let { host, port, user, charset, passwd: password, db: database } = item
|
||||
|
|
|
@ -23,23 +23,23 @@ class Method {
|
|||
}
|
||||
|
||||
connect() {
|
||||
this.defer = Promise.defer()
|
||||
const defer = Promise.defer()
|
||||
this.pool.getConnection(this.slave, (err, conn) => {
|
||||
if (err) {
|
||||
return this.defer.reject(new SqlErr(`MySQL connect ${err}`))
|
||||
return defer.reject(new SqlErr(`MySQL connect ${err}`))
|
||||
}
|
||||
if (this.db) {
|
||||
conn.query('USE ' + this.db, err => {
|
||||
if (err) {
|
||||
return this.defer.reject(new SqlErr('Select DB ' + err))
|
||||
return defer.reject(new SqlErr('Select DB ' + err))
|
||||
}
|
||||
this.defer.resolve(conn)
|
||||
defer.resolve(conn)
|
||||
})
|
||||
} else {
|
||||
this.defer.resolve(conn)
|
||||
defer.resolve(conn)
|
||||
}
|
||||
})
|
||||
return this.defer.promise
|
||||
return defer.promise
|
||||
}
|
||||
|
||||
listDb() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mysqli",
|
||||
"version": "2.1.3",
|
||||
"version": "2.2.0",
|
||||
"description": "MySQL tool",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
|
Loading…
Reference in New Issue