Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql gem vs mysql2 gem and 'each_hash' method

Previously I have used mysql RubyGem in my app. Now I have switched to mysql2 RubyGem and I'm having problems with Result class.

Code example:

db_values = ActiveRecord::Base.connection.execute(sql)

db_values.each_hash do |db_value|
  ret_val << MyValue.do_smth_with_data(db_value)
end

Previously (in mysql RubyGem) there was each_hash method for looping through the data. In mysql2 RubyGem there is just a 3 possible methods (count, each, fields) for Result class and one of them is each method, but that is not what I need to loop fetched data.

Any suggestion?

like image 226
thesis Avatar asked Dec 28 '22 16:12

thesis


1 Answers

the mysql2 gem includes the Enumerable module, so you just use each instead of each_hash.

like image 135
brianmario Avatar answered Dec 30 '22 07:12

brianmario