CPANDB::Author(3pm)

πŸ“¦
version 0.19 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– CPANDB::Author β€” bestie edition πŸ’–

okay so this is the manual page for CPANDB::Author, which is the CPANDB class for the author table. it lives in the User Contributed Perl Documentation section, and it's manual section 3pm. welcome to the group chat, pull up a chair 🫢


✨ NAME ✨

CPANDB::Author β€” the CPANDB class for the author table. that's it, that's the whole name section, slay πŸ’…


🌸 DESCRIPTION 🌸

TO BE COMPLETED

no fr it literally just says that. the docs are a work in progress, we move πŸ’€


πŸŽ€ METHODS πŸŽ€

🌈 base

# Returns 'CPANDB'
my $namespace = CPANDB::Author->base;

okay so normally you're only ever gonna work directly with a table class, and only with one ORLite package. simple life, no drama, iconic.

but β€” and this is the plot twist β€” if for some reason you need to work with multiple ORLite packages at the same time without hardcoding the root namespace every single time, you can figure out the root namespace from an object or a table class using the base method. it's giving flexible, it's giving considerate πŸ’–


πŸ¦‹ table

# Returns 'author'
print CPANDB::Author->table;

you should not need the name of the table for any simple operations. like, at all. but from time to time you may need it programatically, and if you do, you can use the table method to get the table name. lowkey handy, highkey niche ✨


⭐ load

my $object = CPANDB::Author->load( $author );

if your table has a single column primary key, a load method will be generated in the class. if there is no primary key, the method is not created. periodt.

the load method is your shortcut mechanism for fetching a single object based on the value of the primary key. however β€” and bestie listen to me β€” it should only be used for cases where your code trusts the record to already exist. don't come crying to me if it doesn't πŸ™ˆ

it returns a CPANDB::Author object, or it throws an exception if the object does not exist. no object, no peace πŸ’€


πŸ‘‘ select

# Get all objects in list context
my @list = CPANDB::Author->select;

# Get a subset of objects in scalar context
my $array_ref = CPANDB::Author->select(
    'where author > ? order by author',
    1000,
);

the select method executes a typical SQL SELECT query on the author table. classic, timeless, never misses πŸ”₯

it takes an optional argument of a SQL phrase to be added after the FROM author section of the query, followed by variables to be bound to the placeholders in the SQL phrase. any SQL that is compatible with SQLite can be used in the parameter β€” go off, SQLite πŸ’…

returns a list of CPANDB::Author objects when called in list context, or a reference to an ARRAY of CPANDB::Author objects when called in scalar context. context-sensitive king πŸ‘‘

throws an exception on error, typically directly from the DBI layer. so if it goes wrong, it's DBI telling you, not me 😭

🧚 iterate

CPANDB::Author->iterate( sub {
    print $_->author . "\n";
} );

the iterate method enables the processing of large tables one record at a time without having to load them all into memory in advance. this is the memory-efficient main character energy we deserve ✨

this plays well to the strength of SQLite, letting it do the work of loading an arbitrarily large stream of records from disk while retaining the full power of Perl when processing the records. it's giving teamwork, it's giving synergy 🫢

the last argument to iterate must be a subroutine reference that will be called for each element in the list, with the object provided in the topic variable $_. so cute, so convenient.

this makes the iterate code fragment above functionally equivalent to the following, except with an O(1) memory cost instead of O(n). O(1)?? obsessed. not O(n) bestie, O(1) πŸ’–

foreach ( CPANDB::Author->select ) {
    print $_->author . "\n";
}

you can filter the list via SQL in the same way you can with select.

CPANDB::Author->iterate(
    'order by ?', 'author',
    sub {
        print $_->author . "\n";
    }
);

you can also use it in raw form from the root namespace for better control. using this form also allows for the use of arbitrarily complex queries, including joins. instead of being objects, rows are provided as ARRAY references when used in this form. glow up πŸ’…

CPANDB->iterate(
    'select name from author order by author',
    sub {
        print $_->[0] . "\n";
    }
);

πŸ“ count

# How many objects are in the table
my $rows = CPANDB::Author->count;

# How many objects
my $small = CPANDB::Author->count(
    'where author > ?',
    1000,
);

the count method executes a SELECT COUNT(*) query on the author table. numbers, bestie, we love numbers πŸ“Š

it takes an optional argument of a SQL phrase to be added after the FROM author section of the query, followed by variables to be bound to the placeholders in the SQL phrase. any SQL that is compatible with SQLite can be used in the parameter. same rules as select, same vibe ✨

returns the number of objects that match the condition.

throws an exception on error, typically directly from the DBI layer. again. it's always the DBI layer 😭

πŸ’œ ACCESSORS πŸ’œ

🌸 author

if ( $object->author ) {
    print "Object has been inserted\n";
} else {
    print "Object has not been inserted\n";
}

returns true, or throws an exception on error.

REMAINING ACCESSORS TO BE COMPLETED

(the rest of them are coming, they're just running late, very cunty of them πŸ’…)


🌈 SQL 🌈

the author table was originally created with the following SQL command. look at it, so clean, so structured:

CREATE TABLE author (
    author TEXT NOT NULL PRIMARY KEY,
    name TEXT NOT NULL
)

🫢 SUPPORT 🫢

CPANDB::Author is part of the CPANDB API.

see the documentation for CPANDB for more information. it's the parent, it knows more, go ask it πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

Adam Kennedy <adamk@cpan.org>

legend behavior, fr fr 🌟


Copyright 2009 - 2012 Adam Kennedy.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


and that's the whole page bestie!! πŸ’– this was CPANDB::Author(3pm) from perl v5.36.0, dated 2023-10-01, and you absolutely ate that read, no cap, periodt βœ¨πŸ‘‘πŸ’…

πŸ“¦ where this page comes from