Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EM::Synchrony::ConnectionPool / last_id after INSERT with mysql2 gem #164

Closed
devmod opened this issue Jul 23, 2013 · 2 comments
Closed

EM::Synchrony::ConnectionPool / last_id after INSERT with mysql2 gem #164

devmod opened this issue Jul 23, 2013 · 2 comments

Comments

@devmod
Copy link

devmod commented Jul 23, 2013

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

@igrigorik
Copy link
Owner

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.

@rubencaro
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants