> will see if I can restructure the code to use such a construct.

It would actually be pretty straightforward, in my code, at least, to 
encapsulate everything from that first write_chunk call down to the initial 
$cb->() invocation as a helper function -- it's all pretty generic -- and 
then that's essentially your "viewer".

> Unfortunately my DB driver is not Mojo::Pg

Doesn't matter.  For our purposes here, Mojo::Pg::Result is just like a DBI 
statement handle, so if you're using DBI directly, just use those, call 
->fetchrow_hashref instead of ->hash, and so on...

Where use of  Mojo::Pg would matter is if you wanted to do things backwards 
and instead of the controller pulling data from the model, you have the 
model pushing data to the controller (sort of like in your code, but 
instead of explicitly passing the controller in you just pass in a callback 
sub that accepts rows of data or an "I'm done now" and issues the 
write_chunk/finish calls accordingly -- point being that this sub then 
lives on the controller side and once again you're keeping the write_chunk 
crap out of the model),... at which point you need a database driver that's 
able to send data back asynchronously, which is a Postgresql feature that's 
being taken advantage of in Mojo::Pg.  Other DB drivers may have something 
similar but you'd have to dig that out yourself

Monday, June 8, 2015 at 7:27:44 PM UTC-7, Allan Cochrane wrote:

> Hi,
>
> I eventually came up with almost the same code except I pushed the writing 
> down to the model whereas you've pulled it up to the controller. I like the 
> idea of a viewer (aka conductor or presenter) and will see if I can 
> restructure the code to use such a construct.
>
> Unfortunately my DB driver is not Mojo::Pg but is ODBC based and in some 
> cases I'm streaming millions of rows of data. Initially I bundled up a few 
> thousand rows before calling to_json to avoid having millions of callbacks 
> on the stack since it looks like a recursive call to the callback but it 
> doesn't seem to be called recursively.
>
> It is annoying not to have a way to just write to the output stream 
> without resorting to callbacks, in this scenario.
>
> Thanks for your help.
>
> Allan
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to