You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Goliath and the mysql2 gem and I need to do an INSERT and retrieve the id of the newly created row.
So far I have done this:
config['db'] = EM::Synchrony::ConnectionPool.new(:size => 5) do
::Mysql2::EM::Client.new(...)
end
...
EM::Synchrony.sync env.db.aquery("INSERT INTO table ...")
last_id = env.db.last_id
From what I read on ConnectionPool, last_id would use any of the available connections on the pool and not the same connection I have just used to do the INSERT. Would this still return the value I am looking for? Even when other INSERTS might have been done on other connections? Or am I misunderstanding something along the way?
Any pointers are greatly appreciated,
Thanks
The text was updated successfully, but these errors were encountered:
Connection pool will grab the first available connection on each call, so the answer is "no", it won't give you the value you're looking for. Having said that, take a look at the implementation of the connection pool itself: it provides an execute method which will yield the connection, which you can then use to issue a query, , and release it.
I had the same problem and ended writing my own connection pool. https://github.com/rubencaro/fiber_connection_pool Take a look. It lets you gather data from the very same connection, just as you ask.
Response on Issue #101
I am using Goliath and the mysql2 gem and I need to do an INSERT and retrieve the id of the newly created row.
So far I have done this:
config['db'] = EM::Synchrony::ConnectionPool.new(:size => 5) do
::Mysql2::EM::Client.new(...)
end
...
EM::Synchrony.sync env.db.aquery("INSERT INTO table ...")
last_id = env.db.last_id
From what I read on ConnectionPool, last_id would use any of the available connections on the pool and not the same connection I have just used to do the INSERT. Would this still return the value I am looking for? Even when other INSERTS might have been done on other connections? Or am I misunderstanding something along the way?
Any pointers are greatly appreciated,
Thanks
The text was updated successfully, but these errors were encountered: