And how about you read the question, Francesco, rather than being rude and 
condescending?

Brian is looking for a way to get the results without loading them all at once, 
not simply how to query the data store.  If the query returned 3 million rows, 
DataObjects would return all 3 mil at once, rather than one at a time.

Maybe you didn't mean to sound rude, but you did.

Brian, looking at the DataObjects code, it appears you can invoke next! 
yourself, but I'm not clear if the result set is buffered or entirely loaded 
into memory.  Here's the implementation of #each, so you can see what's going 
on when you iterate normally:

https://github.com/datamapper/do/blob/master/data_objects/lib/data_objects/reader.rb#L33-44

It's a bit clunky (call #next!, then fetch #fields and #values and zip them 
together).

Chris


Il giorno 27/feb/2012, alle ore 08:19, Francesco Vollero ha scritto:

> On Sat, Feb 25, 2012 at 3:12 AM, Brian Stokes <bsto...@gmail.com> wrote:
>> I have a complicated reporting query that is just much easier for me to deal
>> with (given our models) as a raw sql query, which I put inside a model and 
>> want
>> to return as an array of hashes.
>> 
>> Got that working. But I get all the rows at once, and I'm worried about 
>> memory.
>> Is there a way, ala DBI module, to loop through the rows from the db handle 
>> as a
>> result set?
>> 
> 
> I suppose you usually don't read the documentation of the libraries
> you're using... I'm saying that, because if you go in this page [1]
> and search for title: "Talking directly to your data-store" you will
> find this solution:
> 
> zoos = repository(:default).adapter.select('SELECT name, open FROM
> zoos WHERE open = 1')
> 
> But to not let you miss all the fun, good reading and next time: RTFM.
> 
> 
>> while row=sth.fetch do
>>   p row
>> end
>> 
>> Thanks!
>> 
> It's a pleasure to help,
> Francesco
> 
> 
> [1] http://datamapper.org/docs/find.html
>> 
>> 
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "DataMapper" group.
>> To post to this group, send email to datamapper@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> datamapper+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/datamapper?hl=en.
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "DataMapper" group.
> To post to this group, send email to datamapper@googlegroups.com.
> To unsubscribe from this group, send email to 
> datamapper+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/datamapper?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to datamapper@googlegroups.com.
To unsubscribe from this group, send email to 
datamapper+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to