On Oct 16, 4:34 pm, Joel VanderWerf <[email protected]> wrote:
> Is it possible to bypass the hash creation when iterating over a
> dataset, and instead yield an array of specified columns to the block,
> like this?
>
> DB[:table].each(:column1, :column2) do |col1, col2| ... end
>
> ISTR seeing something like this somewhere, but can't find it in the rdoc
> now.
No. When I took over maintenance, Sequel supported yielding arrays
with keys instead of hashes (as an option), but it wasn't used by
anyone, was flawed by design, and was broken in parts when I took over
maintenance. According to the CHANGELOG, it was removed in 1.5.0.
It's fairly easy to add a method that does this:
class Sequel::Dataset
def each_cols(*cols)
each{|r| yield(*r.values_at(*cols))}
end
end
That won't work on model datasets, though. If you want a version that
works on any dataset, you need to call fetch_rows instead.
Also, it doesn't bypass hash creation. To do that would require
adapter-specific code inside fetch_rows.
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
-~----------~----~----~----~------~----~------~--~---