The situation I'm facing is the following:
- Initialize a database connection:
DB = Sequel.connect('<my-connection-string>')
- Use it for raw queries as usual (SQL in this case):
DB['SELECT * FROM my-db'].each do |row|
puts 'It works (as it should)'
end
- Disconnect all the connections from that DB's pool:
DB.disconnect
- Use again the disconnected DB object for querying (without explicitly connecting again):
DB['SELECT * FROM my-db'].each do |row|
puts 'It STILL works (I did not expect it)'
end
As I'm observing in my connections inspector, even after disconnecting, re-using the object ends up in opening a new connection to the same DB the object was initially configured to connect, and everything works just fine.
I ended up here by configuring a simple connection at initialize time in a class but closing it after each iteration on a loop of queries, and to my surprise it worked fine without any complains.
My question is: is this how it is supposed to behave? Is this documented behavior or is just undefined behavior which, due to good design patterns (I guess?) from Sequel's side, ends up in consistent behavior? So far I haven't been able to find anything, neither in Sequel's documentation nor in SO.
I'd like to keep on using this format (since it saves quite a lot of code lines in my specific case), but only if it is something reliable.