I'm trying to figure out how best to get a connection to my databases.
Right now I have a method that parses the URL (depending on the URL that the application should connect to another database, for example client1.example.com will connect to customer1 database) and calls
ActiveRecord::Base.establish_connection(conn_string)
where conn_string contains the database name.
This method (set_db) is called using
before_filter :set_db
in my application controller, so basically for every request I receive, the URL is parsed and the application is trying to set connection_connection.
I was wondering if I have a connection pool somewhere ... do you have any suggestions on this? Is it better to have a singleton that supports all connections and returns the correct one?
Thanks! Roberto
source
share