| Class-DBI-Lite documentation | view source | Contained in the Class-DBI-Lite distribution. |
Class::DBI::Lite::Pager - Page through your records, easily.
# Fetch 300,000,000 records, 100 records at a time:
my $pager = app::citizen->pager({
country => 'USA'
}, {
order_by => 'last_name, first_name',
page_size => 100,
page_number => 1,
});
while( my @people = $pager->next_page ) {
# We only got 100 people, instead of swamping the
# database by asking for 300M records all at once:
}
Paging through records should be easy. Class::DBI::Lite::Pager makes it easy.
This has been tested with MySQL 5.x and SQLite. It should work with any database
that provides some kind of LIMIT index, offset construct.
To discover the total number of pages and items, 2 queries must be performed:
SELECT COUNT(*) ... to find out how many items there are in total.If running 2 queries is going to cause your database server to catch fire, please consider rolling your own pager or finding some other method of doing this.
Returns a new Pager object at the page number and page size specified.
Read only. Returns the page number.
Read only. Returns the page size.
Read only. Returns the total number of pages in the Pager.
Read only. Returns the total number of records in all the pages combined.
Read only. Returns the index of the first item in this page's records.
Read only. Returns the index of the last item in this page's records.
Read only. Returns true or false depending on whether there are more pages after the current page.
Read only. Returns true or false depending on whether there are more pages before the current page.
Returns the next page of results. Same as calling next_page(). Purely for syntax alone.
Returns the next page of results. If called in list context, returns an array. If called in scalar context, returns a Class::DBI::Lite::Iterator.
If there is not a next page, returns undef.
Returns the previous page of results. If called in list context, returns an array. If called in scalar context, returns a Class::DBI::Lite::Iterator.
If there is not a previous page, returns undef.
Copyright John Drago <jdrago_999@yahoo.com>. All rights reserved.
This software is Free software and may be used and redistributed under the same terms as perl itself.
| Class-DBI-Lite documentation | view source | Contained in the Class-DBI-Lite distribution. |