开发者

Extract data from Mysql::Object in ruby on rails

开发者 https://www.devze.com 2022-12-22 06:41 出处:网络
开发者_StackOverflow中文版I have code to run sql query in ruby as follows sql = ActiveRecord::Base.connection()
开发者_StackOverflow中文版

I have code to run sql query in ruby as follows

sql = ActiveRecord::Base.connection()

sql.begin_db_transaction

report = sql.execute("select * from users;")

sql.commit_db_transaction

So after this report is an Mysql::object. Now I want to extract all fields and its corresponding data to array or hash.

thanks,


execute method should produce a result which gives you a method called all_hashes - it will return an array of hashes corresponding to the rows of query's results, which seems to be what you need. So, call

report.all_hashes
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号