Actually there are issues with it. If you use the gem mysql2, for example, you'll start seeing some errors like:
Mysql2::Error This connection is still waiting for a result
Please use this instead. It was written by Mike Perham, all credits to him.
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
You'll need to install gem connection_pool
too.
This will spare you from many headaches.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…