[Maypole] no use of LIMIT in sql queries
Yuval Kogman
nothingmuch@woobling.org
Wed, 30 Jun 2004 15:43:35 +0300
--u3/rZRmxL6MmkK24
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Wed, Jun 30, 2004 at 00:29:36 +0100, Simon Cozens wrote:
> What we need is some kind of Class::DBI Pager system.
My dream pager is an iterator subclass:
package MyApp::Pager;
Class::DBI::Iterator::Paginated; # mixin (not yet written)
use base 'Class::DBI::Iterator';
=09
# create the defaults for your app
sub items_per_page { 25 }; # or using class data
package MyApp::DBI;
__PACKAGE__->iterator_class('MyApp::Pager');
# ...
my $pager =3D CDBI->retrieve_all(); # or search, or whatever
$pager->current_page($cgi_param);
print "next page is ", $pager->next_page if $pager->next_page;
foreach my $obj (@$pager){ # overloaded to ->page_items
}
it doesn't fix the list context version of retrieve_all, but it should
be a very easy subclass to Class::DBI::Iterator. CDBI::Iterator has lots
of places where efficiency could be improved, too.
This interface doesn't lock out the possibility of using database
dependant optimisations (MySQL has some features that can be used),
offset/limit instead of fetching by ID, and so forth.
One required change is that sth_to_objects should not load the whole
table of primary keys first - this can be lazyloaded with a slightly
different interface, or resolved differently alltogether (by moving some
knowlege about the query to the iterator). If this is achieved, the
requirements of the email that started this thread should be fullfilled.
I will have a need for this myself, pretty soon, so I promise to write
it if it hasn't been done by then. The reason I don't like
Class::DBI::Pager so much is that it will be very hard to make it
smarter.
--=20
() Yuval Kogman <nothingmuch@woobling.org> 0xEBD27418 perl hacker &
/\ kung foo master: *shu*rik*en*sh*u*rik*en*s*hur*i*ke*n*: neeyah!!!!
--u3/rZRmxL6MmkK24
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFA4rV3VCwRwOvSdBgRApHCAJ9Q/C1DCdXv1ZNSadd5eNHr17s4bACgtCER
rXHovENapT4As/TfS7wNFvA=
=pjDZ
-----END PGP SIGNATURE-----
--u3/rZRmxL6MmkK24--