[Dbix-class] paging question

Andrey Kostenko andrey at kostenko.name
Tue Feb 2 20:17:26 GMT 2010


02.02.10 22:58, James Marca написав(ла):
> On Tue, Feb 02, 2010 at 11:14:27AM -0800, James Marca wrote:
>    
>> Hi.
>>
>> First DBIx::Class is excellent and kudos all around.
>>
>> I have recently needed to use the paging feature for the first time
>> and I'm not sure of the best way to do this.
>>
>> First a simple question:  How should one terminate the paging?  Is
>> there some variable to check to find out how many pages of data are
>> expected from a result set?  I couldn't find anything in the docs,
>> but I probably missed it.
>>      
> Clarifying my question... I am aware of the ability to call
>
> my $data_page_object = $rs->pager();
> my $total_count = $data_page_object->total_entries();
>
> But that looks like it will hit the database once with a count(*)
> select call, which in PostgreSQL is expensive.  What I am hoping for
> is something along the lines of
>
> my $paged_rs = $rs->page($nextpage);
> if (! $paged_rs || ! $paged_rs->no_more_data ){
>    return;
>    # undefined page result set means I've gone beyond the max pages
>    # while calling $paged_rs->first would hit the db with that
>    # expensive query
> }
>
> No, I have no idea how to get that result without asking for it
> explicitly from the db, but just because I can't figure that out
> doesn't mean it is impossible!
>
> Regards,
> James
>
>
>    
You can override method "pager" in your resultsets and write your own code.
You can create triggered counters for your records. E.g. "count" field 
in table "threads", which you will access in pager method.



More information about the DBIx-Class mailing list