I am using the Ruby mysql2 gem found here: https://github.com/brianmario/mysql2
I have the following code:
client = Mysql2::Client.new( :host => dbhost, :port => dbport, :database => dbname, :username => dbuser, :password => dbpass) sql = "SELECT column1, column2, column3 FROM table WHERE id=#{id}" res = client.query(sql, :as => :array) p res
Is it possible that the above .query call returns an hash array, each hash in the res array should be in the format column => value . I can do this manually, but from the documents I have the impression that I can get the results directly loaded into memory in the specified format. I need this because after that I still need to code the result in json, so for me there is no advantage to getting strings one by one. Also, the amount of data is always very small.
source share