According to http://tmtm.org/en/mysql/ruby/, the results have a "each_hash" method, but statements do not. What a pain in the ass ...
#A proxy for the statement class class Stmt def each_hash fields = @target.result_metadata.fetch_fields.map do |f| f.name.to_sym end @target.execute.each do |x| hash = {} fields.zip(x).each do |pair| hash[pair[0]] = pair[1] end yield hash end end def initialize(target) @target = target end def method_missing(name, *args, &block) @target.send(name, *args, &block) end end
Now you can do this:
Stmt.new(@db.prepare(...).execute(...)).each_hash do |x| puts x end
and you can scroll each line as a hash.
I still have not tested this for several performances
source share