node mssql 连接池
generic-pool模块是nodejs的一个兆孝第三方闹敬模块,其作用为提供一个通用的连接族弯稿池模块,可以通过generic-pool实现对tcp连接池或者MySQL数据库连接池等的管理。github的地址如下:
// Create a MySQL connection pool with
// a max of 10 connections, a min of 2, and a 30 second max idle time
var Pool = require('generic-pool').Pool;
var mysql = require('mysql'); // v2.10.x
var pool = new Pool({
name : 'mysql',
create : function(callback) {
var c = mysql.createConnection({
user: 'scott',
password: 'tiger',
database:'mydb'
})
// parameter order: err, resource
callback(null, c);
},
destroy : function(client) { client.end(); },
max : 10,
// optional. if you set this, make sure to drain() (see step 3)
min : 2,
// specifies how long a resource can stay idle in pool before being removed
idleTimeoutMillis : 30000,
// if true, logs via console.log - can also be a function
log : true
});