Closed malikimprowised closed 7 years ago
Currently, no. I think I have seen something like the before in resource pool libs in other languages. What sort of (external) API would you imagine this having? I'm not against adding some support for this.
When inserting connections into the pool, allowing for a type system would be nice. Then, when you need a connection, you could pass in an optional filter and you would get a connection that matches.
Possible example Creating
var pool = new Pool([{
name : 'mysql-master',
type: 'write',
create : function(callback) {
var c = mysql.createConnection({
//....
})
callback(null, c);
},
name : 'mysql-replica',
type: 'read',
create : function(callback) {
var c = mysql.createConnection({
//....
})
callback(null, c);
},
], //...
});
Acquiring
pool.acquire({ type: 'write'}, function(err, client) {
//....
});
Something like that
This seems like a lot of complexity compared to:
const readPool = new Pool({/* .. opts... /*})
const writePool = new Pool({/* .. opts... /*}
and I'm not sure what advantages it would give?
Yea you're probably right. Best not to over complicate things!
If such an API / functionality was useful to you/anyone I think it would be better done as wrapper/proxy/thing/lib/module thing infront of generic-pool
, and doing so would probably make it pretty simple?
Is it possible to have one pool that include multiple database replicas which has different host and port and divert the query among them using some sort of algorithm?