On Fri, Jul 10, 2009 at 1:35 AM, jimeh<[email protected]> wrote: > > Yeah, you are right. And for the record, I'm not 100% familiar with > this code, as someone else originally wrote it, and I was tasked with > fixing the database connection issue. > > Here's part of the code: > > # before filter > before do > �...@db = Sequel.mysql("database", > :user => "root", :password => "", > :host => "localhost", :max_connections => 10, > :loggers => [Logger.new($stdout)], > :timeout => 4 > ) > �...@user = id_user(params[:user_id]) > end
There's the problem. Move that @db= outside the before filter and use a constant instead: DB = Sequel.mysql(.....) before do @user = id_user(params[:user_id]) end > > # api post request definition > post "/api/:function" do > # do stuff > end > > # fetch user > def id_user(user_id) > users = @db.from(:users) > return users.filter(:id => user_id).first > end and use the single connection here: def id_user(user_id) DB[:users][:id => user_id] end > > > Thanks :) > > > > On Jul 9, 7:53 pm, Jeremy Evans <[email protected]> wrote: >> On Jul 9, 4:17 pm, jimeh <[email protected]> wrote: >> >> > We are using Sinatra and Sequel for a small API implementation. The >> > problem we have however is that on every page request Sequel opens new >> > connections to MySQL, and keeps them open till they timeout, or you >> > restart Apache. >> >> > There's not a lot of documentation on how to reuse connections, so any >> > help, explanations, and/or pointers in the right direction would help. >> >> That's certainly not how Sequel is designed to work. My guess is that >> you are calling the connect method (and instantiating a new >> Sequel::Database object) on every page request, instead of only once >> at startup. You'll have to post/pastie some code for a more accurate >> diagnosis. >> >> Jeremy > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
