Alzabo...Cursor(3pm)

๐Ÿ“ฆ
version 0.92 ยท 2 versions
  • 0.92 ยท debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.92 ยท ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– Alzabo::Runtime::RowCursor โ€” the 3pm page, but make it cute ๐Ÿ’–

okay bestie, so this is the manual page for Alzabo::Runtime::RowCursor from the User Contributed Perl Documentation collection, and no cap, it's actually kinda iconic. sit down, grab a strawberry ๐Ÿ“, and let's get into it.


โœจ NAME โœจ

Alzabo::Runtime::RowCursor โ€” it's a cursor that hands you back Alzabo::Runtime::Row objects ๐Ÿ’…

Like, that's literally its whole job. A cursor. For rows. Row cursor. The name ate fr fr.


๐ŸŒธ SYNOPSIS ๐ŸŒธ

here's the vibe in code form, copy it exactly bestie:

use Alzabo::Runtime::RowCursor;

my $cursor = $schema->table('foo')->all_rows;

while ( my $row = $cursor->next )
{
    print $row->select('foo'), "\n";
}

see how we're just looping? next keeps giving you rows until it gives you undef and the while bails out. chef's kiss. ๐Ÿ‘‘


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so, objects in this class exist to return Alzabo::Runtime::Row objects for your queries. that's the assignment. ๐ŸŽ€

and here's the part that's lowkey genius: the cursor does NOT preload objects. it creates them on demand, which is much more efficient. it's giving "why make 500 rows when you might only need 3" energy. main character resource management honestly.

if you want the whole deep dive on why this is the move, go read the RATIONALE FOR CURSORS section over in Alzabo::Design. iykyk.


๐ŸŒˆ INHERITS FROM ๐ŸŒˆ

Alzabo::Runtime::Cursor โ€” yeah she got it from her mama. ๐Ÿ’œ


๐Ÿ’… METHODS ๐Ÿ’…

next

returns the next Alzabo::Runtime::Row object, or undef if there are no more available. that undef is the "we're done here" signal, so don't sleep on checking for it.

all_rows

returns all the rows available from the current point onwards. โญ

and this is the important little detail bestie, pay attention: it means that if there are five rows that will be returned when the object is created, and you call next twice, then calling all_rows after that will only return three. the cursor remembers where it's at. no rewinding, no do-overs.

reset

resets the cursor so that the next next call will return the first row of the set. it's the little rewind button. ๐Ÿ”„โœจ

count

returns the number of rows returned by the cursor so far. so far!! not the total!! she's counting what she's already handed you. ๐Ÿงฎ

next_as_hash

returns the next row as a hash, where the hash key is the table name and the hash value is the row object. cute little key-value packaging, obsessed. ๐ŸŽ


๐Ÿซถ AUTHOR ๐Ÿซถ

Dave Rolsky, <autarch@urth.org> โ€” thank you for your service king ๐Ÿ’–


heads up bestie: that email address goes in exactly as written, autarch@urth.org, no edits, no autocorrect, we respect the author. ๐Ÿ˜Œ

okay that's the whole page, you understood all of it, slay. ๐ŸŽ€โœจ

perl v5.34.0, dated 2022-06-14 โ€” and that's the footer, so mwah, thanks for reading, go forth and iterate responsibly ๐Ÿฆ‹๐Ÿ’œ๐ŸŒธ

๐Ÿ“ฆ where this page comes from