0
点赞
收藏
分享

微信扫一扫

node.js的generic-pool与mysql结合,mysql连接池

程序猿不脱发2 2023-02-03 阅读 27

var generic_pool = require('generic-pool');
var pool = generic_pool.Pool({
name: 'mysql',
max: 10,
create: function(callback) {
var Client = require('mysql').createConnection({
host:'127.0.0.1',

user:'root',

password:'123456',

database: 'weibo_gs'

});
callback(null,Client);
},
destroy: function(db) {
db.disconnect();
}
});

pool.acquire(function(err, client) {
if (err) {
// handle error - this is generally the err from your

// factory.create function
}
else {
client.query("select * from gs_scrapy", [], function(err,data) {
console.log(data);
// return object back to pool
pool.release(client);
});
}
});

举报

相关推荐

0 条评论