Closed xum07 closed 1 year ago
I don't really see a problem here. Getting a session from the connection pool and giving it back is already handled via soci::session
's constructor and destructor in a very convenient way (see https://soci.sourceforge.net/doc/release/4.0/multithreading/):
{
session sql(pool);
sql << "select something from somewhere...";
} // session is returned to the pool automatically
It's not problem, but an unfriendly way.
As I said, user don't need to know what is the meaning of position, that getted by at()
, in the connect pool. It is related to connect pool inner implement. If connect pool does not use a std::vector
as its container, the interface has to change.
I also don't really see a problem. I agree that the API is not very elegant, but you should consider the index to be just an opaque "cookie", i.e. something you get from the library and then give back to it, you don't need to know anything about how it's used and what the implementation is like.
But there are no redundant steps here AFAICS, so closing.
Current interface of connect pool is not friendly enough. To get a session, user must do 2 steps:
lease()
ortry_lease()
to get a index of sessions;at()
to get the sessionA better design should be:
session& lease(std::size_t)
void give_back(session&)
The change needs to wrap the original
session
with a private memberposition
. There is no reason to expose the internal index of sessions in the connection pool to user