如何在node-mysql中建立池连接? 任何人都可以提供语法吗?
答案 0 :(得分:1)
试试这个:
function Pool(num_conns)
{
this.pool = [];
for(var i=0; i < num_conns; ++i)
this.pool.push(createConnection()); // your new Client + auth
this.last = 0;
}
Pool.prototype.get = function()
{
var cli = this.pool[this.last];
this.last++;
if (this.last == this.pool.length) // cyclic increment
this.last = 0;
return cli;
}