From: Kirk Haines Date: 2004-08-09T04:21:40+09:00 Subject: Re: ANN: Iowa 0.9 Released On Mon, 9 Aug 2004 02:40:41 +0900, Michael Neumann wrote > Michael Neumann wrote: > > Kirk Haines wrote: > > May I ask another question? ;-) > > I'd like to use Active Records with IOWA. Have you tried it out? I > know that there's Kansas... but I like AR very much. I probably have > to write my own session class which connects to the database and set > AR's connection to this one for each request. I believe that each > request is handled by it's own thread, but all request of the same > session are not handled by one and the same thread, right? Right. Each seperate request is handled by a thread that terminates after the response is sent back. I looked at Active Record some time ago, but not enough details are popping into my head at the moment to be sure this is right, but... If you use the Iowa connection pool, DbPool, you can probably make use of something that I did for it to support Kansas to also support ActiveRecord. In your Iowa::Application subclass: attr_accessor :dbpool def initialize(*args) @dbpool = Iowa::DbPool.new ('Mysql','localhost','mydb','myuser','mypwd',3,300) {|dbh| # The 3 is the number of connections in the pool, and the # 300 is the number of seconds that a reaper thread sleeps # between checks for connections that have become orphaned # and hanged. # This block will be executed when the connection pool # creates its connections. It receives the database handle # and can then do anything to it that it wants. Whatever # is returned from the block is what the connection pool # will actually store in the pool. # # So, at this point, use the connection to setup your AR # connection, I believe. ar_connection } Something like that should let you use the connection pool with ActiveRecord. Then, in your code, when you need to do something with the database: application.dbpool.getConnection do |ar_connection| # do your queries end Make sense? That's exactly how I do it with Kansas, and it works well and lets me keep the number of db connections very low. If you try it and it works, let me know and send me the code and I'll get something added to the documentation that specifically addresses using ActiveRecord with Iowa. Thanks, Kirk Haines