Em 27-04-2012 13:47, Jeremy Evans escreveu:
On Friday, April 27, 2012 9:23:13 AM UTC-7, Rodrigo Rosenfeld Rosas
wrote:
I can get the sandbox information through
"Rails.application.sandbox?". Could you give an example on how to
use this Sequel's "after_connect" hook to ensure it will be inside
a transaction?
DB.pool.after_connect = proc do |conn|
DB.send(:add_transaction, conn, {})
DB.send(:begin_transaction, conn, {})
end
DB.disconnect # remove existing connections
So would the DB.disconnect be called in an at_exit hook? I guess it
would automatically close the connections on program exit without
automatically committing changes, right? So I might just ignore the
'DB.disconnect' code I guess...
Correct use would also check if there is a current after_connect proc
and call it as well if so. Sequel stores all connected databases in
Sequel::DATABASES, so you could iterate over that array to sandbox all
databases. That should fix both of the major issues with the Rails
approach.
Note that this is not fool proof:
DB << 'COMMIT'
Yes, I know :D I don't care, I'm not a fool (hopefully) :D
Thanks once more :) I'll have to pay you tons of beers when you decide
to come visit me in Brazil :) I'll gladly do so then :)
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.