Skip to content

Instantly share code, notes, and snippets.

@owenthereal
Last active December 23, 2015 08:58
Show Gist options
  • Save owenthereal/6610970 to your computer and use it in GitHub Desktop.
Save owenthereal/6610970 to your computer and use it in GitHub Desktop.
Quickly get it to work
config1 = { :database => "db1", :host => "localhost", :port => 15432 }
spec1 = ActiveRecord::Base::ConnectionSpecification.new(config1, "postgresql_connection")
handler1 = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
handler1.establish_connection("db1", spec1)
handler1.connection_pools.values.first.with_connection { ... }
config2 = { :database => "db2", :host => "localhost", :port => 15432 }
spec2 = ActiveRecord::Base::ConnectionSpecification.new(config2, "postgresql_connection")
handler2 = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
handler2.establish_connection("db2", spec2)
handler2.connection_pools.values.first.with_connection { ... }
# rails runner multiple_connection_pools.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment