On Oct 21, 11:44 pm, Jake Mallory <[email protected]> wrote:
> I found that if I used #fetch then called #each on the results I would
> be walking through the records using a cursor.
>
> results = db.fetch(sql)
> results.each{|r| doing_something }
Sequel doesn't actually use a cursor, but the mysql driver might be
internally. Sequel just iterates over the dataset's records (db.fetch
creates a dataset) as the database adapter provides them.
> If you add #all to the fetch it dumps all the records and works with
> them in memory
>
> results = db.fetch(sql).all
> results.each{|r| doing_something }
>
> I'm now working on a project that is using models and can't figure out
> how to work with a collection of models using a cursor similar to the
> above example. Any ideas?
Model.with_sql(sql).each{|r| doing_something }
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
-~----------~----~----~----~------~----~------~--~---