Class::...terator(3)

πŸ’– Class::DBI::Iterator πŸ’–

okay so this is the User Contributed Perl Documentation page for Class::DBI::Iterator, and it’s literally here to make iterating over your Class::DBI search results a whole vibe. ✨

🌸 NAME 🌸

Class::DBI::Iterator β€” iterate over Class::DBI search results. no cap, that’s the whole name. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

        my $it = My::Class->search(foo => 'bar');

        my $results = $it->count;

        my $first_result = $it->first;
        while ($it->next) { ... }

        my @slice = $it->slice(10,19);
        my $slice = $it->slice(10,19);

        $it->reset;

        $it->delete_all;

✨ DESCRIPTION ✨

okay bestie, here’s the tea: any Class::DBI search (including a has_many method) which returns multiple objects can be made to return an iterator instead, simply by executing the search in scalar context. 🫢

Then, instead of having to fetch all the results at the same time, you can fetch them one at a time. That can potentially save a considerable amount of processing time and memory. lowkey iconic. πŸ”₯

πŸ’€ CAVEAT πŸ’€

note note note: there is no provision for the data changing (or even being deleted) in the database inbetween performing the search and retrieving the next result. like, none. so keep that in mind, fr fr. 😭

kisses and sparkles, this page comes from perl v5.42.0 and is dated 2011-04-08 πŸ’‹πŸŽ€

πŸ“¦ where this page comes from