On 2 February 2010 20:58, James Marca <jma...@translab.its.uci.edu> wrote:
> 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!

Ive implemented this type of thing outside of DBIx by limiting the
query to one more record than I intend to page.

This works nicely as it does two things. First it gives me a flag
which i can use to decide whether a page need a "show next page link",
and it gives me an item that i can use to prekey the paging so it does
NOT use the offset/limit form, and instead uses the id of the flag
record to do an indexed search from where the next page starts.

Yves







-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to