find_by_sql suggestions needed

I have an application that generates an ever growing list of stock reports. I find myself some method in a controller creating a connection to the database (postgres in this case), executing a custom sql, using the data returned to create one or more graphs with gruff, and sending them off to be displayed.

This puts the creation of a connection to the database, and the actual sql in the controller. I am not sure that this is such a good idea. I am looking for suggestions on a better approach.

Should I create a separate class with a method to match each arbitrary sql returning the data from a method call?

Should the queries be converted to stored functions which then get called from the controller, or a separate class?

Insights would be appreciated.

Cheers--

Charles