# A Ruby function for assigning a query to an array?

**URL:** <https://www.ruby-forum.com/t/a-ruby-function-for-assigning-a-query-to-an-array/145190>\
**Category:** Ruby\
**Created:** [August 6, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/a-ruby-function-for-assigning-a-query-to-an-array/145190 "2008-08-06T19:13:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ryank](https://www.ruby-forum.com/u/ryank)\
**Post date:** [August 6, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/a-ruby-function-for-assigning-a-query-to-an-array/145190/1 "2008-08-06T19:13:54Z")

</div>

I am wondering if anyone knows of a function for push a MySQL query  
result to an array? Right now I have to loop through the result, not bad  
but somewhat ugly and annoying for naming standards.

Regards,

Ryan

---

<div class="post-metadata">

**Author:** ![ryank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ryank](https://www.ruby-forum.com/u/ryank)\
**Post date:** [August 6, 2008, 8:30pm UTC](https://www.ruby-forum.com/t/a-ruby-function-for-assigning-a-query-to-an-array/145190/2 "2008-08-06T20:30:38Z")

</div>

On Wed, Aug 6, 2008 at 11:11 AM, Ryan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am wondering if anyone knows of a function for push a MySQL query result  
> to an array? Right now I have to loop through the result, not bad but  
> somewhat ugly and annoying for naming standards.
> 
> Regards,
> 
> Ryan

I would suggest trying one of the many ORM libraries out there: Sequel,  
DataMapper, ActiveRecord…

Usually they will give you your results in some array of hashes form.

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![ryank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ryank](https://www.ruby-forum.com/u/ryank)\
**Post date:** [August 6, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/a-ruby-function-for-assigning-a-query-to-an-array/145190/3 "2008-08-06T20:34:09Z")

</div>

Funny you should say that because the moment after I sent that out I got  
an email from Jeremy E. that was posting to the list about Sequel  
2.4.0 release. I had a good laugh. Thanks for the suggestions though.

Regards,

Ryan
