> > The approach I use in my projects it to combine Sequel's SQL
> > generation with the em-mysqlasyncapi:
>
> > EventedMysql.select( User.where(:age > 10).limit(10).sql ) do |rows|
> >   rows.each do |data|
> >     user = User.load(data)
> >     p user.age
> >   end
> > end
>
> You may be able to make this even nicer:
>
>   class Sequel::MySQL::Dataset
>     def execute(sql)
>       EventedMysql.select(sql){|r| yield r}
>     end
>   end
>   User.where(:age > 10).limit(10).each{|user| p user.age}
>
> Not sure if that would work or not, but it would make the code a lot
> nicer.  You'll obviously need to handle deletes, inserts and updates
> differently, you can override execute_dui or another method for those.

This would work, but it tends to break existing code since the query
is no longer blocking. Any code following the #each will be executed
immediately, even before the query's results are returned and looped
over.

I'm using a simple monkey-patch (with sequel 2.1.0) to add an
additional async api to Dataset and Model:
http://github.com/tmm1/em-mysql/tree/master/lib/sequel/async.rb

  DB[:table].where(:id < 100).async_update do |num_updated|
    p "done updating #{num_updated} rows"
  end

  User.async_each do |user|
    user.async_update(:age => rand(100)){ p "#{user.name}'s age set to
#{user.age}" }
  end

  p "this will be printed out before either query is completed"

  Aman
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to