I'd like to pass a column list into a Dataset#select as an array, so that I
have better control of which columns will be selected, e.g.:
columns_wanted = [:id, :name]
columns_wanted << :address if include_address?
rows = DB[:entries].select(columns_wanted)
This currently returns rows in an unexpected format:
DB[:entries].select(columns_wanted).first
=> {:row=>"(1,\"Some One\",\"825 Victoria Ln\")"}
Whereas columns specified as individual arguments returns the desired
format:
DB[:entries].select(:id, :name, :address).first
=> {:id=>"1", :name=>"Some One", :address=>"825 Victoria Ln"}
Would this change break other use cases?
columns.each do |i|
- i.is_a?(Hash) ? m.concat(i.map{|k, v|
SQL::AliasedExpression.new(k,v)}) : m << i
+ if i.is_a?(Hash)
+ m.concat(i.map{|k, v| SQL::AliasedExpression.new(k,v)})
+ elsif i.is_a?(Array)
+ m.concat(i)
+ else
+ m << i
+ end
end
Thanks,
Andrew
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/yBAjbMvhugMJ.
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.