Class::DBI::Pg(3pm)

πŸ“¦
version 0.09 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Class::DBI::Pg β€” the manual, but make it cute πŸ’–

okay bestie, so this is Class::DBI::Pg(3pm) β€” part of the User Contributed Perl Documentation, and it's literally the glow-up your Postgres + Class::DBI setup has been begging for. sit down, grab a strawberry drink πŸ“, and let's get into it.


✨ NAME ✨

Class::DBI::Pg β€” a Class::DBI extension, but make it Postgres πŸ˜πŸ’…


🌸 SYNOPSIS 🌸

like, here's the whole vibe in four lines:

use strict;
use base qw(Class::DBI::Pg);

__PACKAGE__->set_db(Main => 'dbi:Pg:dbname=dbname', 'user', 'password');
__PACKAGE__->set_up_table('film');

that's it. that's the post. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so Class::DBI::Pg automates the setup of Class::DBI columns and primary key for Postgres. it just… does it for you. no cap. πŸ”₯

it selects the Postgres system catalog and finds out all the columns, the primary key, and any SERIAL type column. iykyk.

then you create the table, bestie:

CREATE TABLE cd (
    id SERIAL NOT NULL PRIMARY KEY,
    title TEXT,
    artist TEXT,
    release_date DATE
);

and then you set up your class:

package CD;
use strict;
use base qw(Class::DBI::Pg);

__PACKAGE__->set_db(Main => 'dbi:Pg:dbname=db', 'user', 'password');
__PACKAGE__->set_up_table('cd');

and this is almost the same as doing it the long way, which looks like this:

package CD;

use strict;
use base qw(Class::DBI);

__PACKAGE__->set_db(Main => 'dbi:Pg:dbname=db', 'user', 'password');
__PACKAGE__->table('cd');
__PACKAGE__->columns(Primary => 'id');
__PACKAGE__->columns(All => qw(id title artist release_date));
__PACKAGE__->sequence('cd_id_seq');

like… the way you don't have to type all that anymore? iconic. main character energy fr fr. πŸ‘‘


πŸŽ€ METHODS πŸŽ€

πŸ’œ set_up_table TABLENAME HASHREF

declares the Class::DBI class specified by TABLENAME. and HASHREF? that's where you can specify options for when you're setting up the table. little customization moment. 🫢

πŸ’– ColumnGroup

you can specify the column group that you want your columns to be in, bestie:

$class->set_up_table($table,  { ColumnGroup => 'Essential' });

the default is 'All' πŸ’«

πŸ’– Primary

this one overrides the primary key setting. super useful when you're working with views instead of tables. yes, views. we love a plot twist. πŸ™ˆ

πŸ’œ pg_version

returns the postgres version that you are currently using. that's it, that's the whole method. short queen behavior. ⭐


🌈 AUTHOR 🌈

Daisuke Maki "dmaki@cpan.org" β€” thank you for your service πŸ«‘πŸ’–


πŸ‘‘ AUTHOR EMERITUS πŸ‘‘

Sebastian Riedel, "sri@oook.de" β€” and IKEBE Tomohiro, "ikebe@edge.co.jp" πŸŽ€


πŸ’… LICENSE πŸ’…

this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt. ✨


πŸ”₯ SEE ALSO πŸ”₯

  • Class::DBI
  • Class::DBI::mysql
  • DBD::Pg

and that's the whole page, bestie!! πŸ’–βœ¨ this was perl v5.34.0, dated 2022-06-11, and it's giving Class::DBI::Pg(3pm) β€” go forth and slay your Postgres setup, no cap πŸ˜πŸ‘‘πŸŽ€

πŸ“¦ where this page comes from