title: How to obtain result as array of Hashes in Ruby (mysql2 gem)
body: <p>I'm using Ruby's mysql2 gem found here:
  <a href="https://github.com/brianmario/mysql2" rel="nofollow noreferrer">https://github.com/brianmario/mysql2</a></p>
  
  <p>I have the following code:</p>
  
  <pre><code>client = Mysql2::Client.new(
    :host =&gt; dbhost, 
    :port =&gt; dbport, :database =&gt; dbname,
    :username =&gt; dbuser, 
    :password =&gt; dbpass)
  sql = "SELECT column1, column2, column3 FROM table WHERE id=#{id}"
  res = client.query(sql, :as =&gt; :array)
  p res # prints #&lt;Mysql2::Result:0x007fa8e514b7d0&gt;
  </code></pre>
  
  <p>Is it possible the above <code>.query</code> call to return array of hashes, each hesh in the <code>res</code> array to be in the format <code>column =&gt; value</code>. I can do this manually but from the docs I was left with the impression that I can get the results directly loaded in memory in the mentioned format. I need this, because after that I have to encode the result in json anyway, so there is no advantage for me to fetch the rows one by one. Also the amount of data is always very small.</p>