Open darkdef opened 2 years ago
Do you still want slave connection to be a pool of database connections? i.e. if there's multiple slave instances, would it still look like a single one to developer?
I think need simple implementation of single connection. And creating Multiconnection (also implementation of ConnectionInterface, but with pool of connections. Inherit or decorator) with inner using instances of singleconnection
Decorator sounds great but the thing is that selecting master or slave depends on the query being made i.e. read queries go to slave, write queries go to master so it's not possible to achieve using just decorator over connection. It should be decorator over query builder.
Yes, there may be problems with the current implementation. But similar functions must be removed from the connection: getMasterPdo, getSlave
Not actual. Interfaces are separated
@darkdef don't you think that current design of ConnectionPoolInterface
doesn't quite get along with Single Responsibility Principle? Say, if I want to use ConnectionPoolInterface
with RR
/Swoole
, and I have only one database, why would I bother with Master/Slave settings
And what's the advantage of $dbPool->useMaster(callable $callback)
over $callback($dbPool->getMaster())
?
Why do you need a connection pool for a single database?
At least in Swoole it's used to reuse connections, so there's no waste of time on establishing connections to db during every new request(you can't use single connection from different coroutines; each new request is handled in new coroutine(well, depends on settings, but it's popular setting) ) Mb I got wrong perception of Connection Pool :thinking: UPD. example of ConnectionPool class in Swoole https://github.com/swoole/library/blob/master/src/core/ConnectionPool.php
You understand the concept correctly.
At the moment, we have tried to keep the functions in the pool interface.
During implementation, there will be refactoring and we will take into account your comment.
Need create separate implementation of Master/Slave connection and remove this magic from current realisation. CQRS - responsibility of user