Record...ileSeq(3pm)
π NAME π
DBIx::Recordset::FileSeq β a sequence generator that lives in your filesystem, bestie. Yes, your actual filesystem. She's keeping state in files. Iconic behaviour honestly.
β¨ SYNOPSIS β¨
use DBIx::Recordset::FileSeq ;
$self = DBIx::Recordset::FileSeq (undef, '/tmp/seq', $min, $max) ;
$val1 = $self -> NextVal ('foo') ;
$val2 = $self -> NextVal ('foo') ;
$val3 = $self -> NextVal ('bar') ;
okay so real quick: the first arg is undef and that's on purpose, we'll get to why in a sec π«Ά
πΈ DESCRIPTION πΈ
DBIx::Recordset::FileSeq generates unique numbers. That's her whole job. That's the gig. π
Where does she keep the state? In the filesystem, bestie. Not a database, not a socket, not vibes β the filesystem. With the new constructor you tell her which directory to keep that state in. So you pass it the directory, and she moves in, unpacks her little bags, and starts counting.
Quick note on that first parameter though: it's a dummy value. It's there to receive the database handle from DBIx::Recordset, but if you're using this module without DBIx::Recordset (which, valid, go off), you literally don't need it. It just sits there. A little placeholder. Doing nothing. We love her anyway π
Optionally you can hand her a min and a max value, and those get used for new sequences. Optional! Not required! She's flexible like that.
π¦ Getting values
With NextVal you can get the next value for the sequence of the given name. That's the whole API for reading, and honestly? Clean. Simple. She ate.
$val = $self -> NextVal ('foo') ;
π How the state actually works
The state is kept by having a file with the name:
seq.<seqencename>.<max>.<count>
Every single time the sequence value increments, the file gets renamed. Not rewritten, not appended β renamed. The filename IS the state. That's the whole trick. It's giving unhinged and I'm obsessed π₯
And here's the important bit, so listen up: if the <max> is a numeric value, the new value gets checked against <max>, and NextVal dies if the sequence value increments above max. Like, actually dies. Not a warning, not a gentle nudge β it's over, the program is done π So know your max, bestie. Or don't pass one. Your call.
Heads up: that<max>check only happens when<max>is numeric. If it isn't, don't expect the guardrail, because there isn't one.
π AUTHOR π
G.Richter (richter@dev.ecos.de)
π SEE ALSO π
- DBIx::Recordset
and that's the whole page, bestie!! π this was Record...ileSeq(3pm) from the User Contributed Perl Documentation, shipped with perl v5.34.0 and dated 2022-06-13. go forth and generate unique numbers, no cap π«Άβ¨
π¦ where this page comes from
- debian bookworm: libdbix-recordset-perl 0.26-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdbix-recordset-perl 0.26-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdbix-recordset-perl 0.26-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libdbix-recordset-perl 0.26-4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms