SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

Reduntant step for connect pool interface #1010

Closed xum07 closed 1 year ago

xum07 commented 1 year ago

Current interface of connect pool is not friendly enough. To get a session, user must do 2 steps:

  1. call lease() or try_lease() to get a index of sessions;
  2. call at() to get the session

A better design should be:

  1. to borrow a session: session& lease(std::size_t)
  2. to return back a session: void give_back(session&)

The change needs to wrap the original session with a private member position. There is no reason to expose the internal index of sessions in the connection pool to user

zann1x commented 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
xum07 commented 1 year ago

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.

vadz commented 1 year ago

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.