Class:...Loader(3pm)

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

🌸 NAME 🌸

okay so bestie, welcome to Class::DBI::Loader β€” it's the dynamic definition of Class::DBI sub classes πŸ’– it lives in the User Contributed Perl Documentation section of the manual (3pm, iykyk).


✨ SYNOPSIS ✨

no thoughts, just vibes and a loader:

  use Class::DBI::Loader;

  my $loader = Class::DBI::Loader->new(
    dsn                     => "dbi:mysql:dbname",
    user                    => "root",
    password                => "",
    options                 => { RaiseError => 1, AutoCommit => 0 },
    namespace               => "Data",
    additional_classes      => qw/Class::DBI::AbstractSearch/, # or arrayref
    additional_base_classes => qw/My::Stuff/, # or arrayref
    left_base_classes       => qw/Class::DBI::Sweet/, # or arrayref
    constraint              => '^foo.*',
    relationships           => 1,
    options                 => { AutoCommit => 1 },
    inflect                 => { child => 'children' },
    require                 => 1
  );
  my $class = $loader->find_class('film'); # $class => Data::Film
  my $obj = $class->retrieve(1);

(yes bestie, options shows up twice up there, that's literally how the page prints it, I'm not touching it πŸ’…)

now the mod_perl arc 🧚 β€” use with mod_perl:

in your startup.pl:

  # load all tables
  use Class::DBI::Loader;
  my $loader = Class::DBI::Loader->new(
    dsn       => "dbi:mysql:dbname",
    user      => "root",
    password  => "",
    namespace => "Data",
  );

in your web application.

  use strict;

  # you can use Data::Film directly
  my $film = Data::Film->retrieve($id);

πŸ¦‹ DESCRIPTION πŸ¦‹

Class::DBI::Loader automates the definition of Class::DBI sub-classes β€” it scans table schemas and sets up columns and the primary key for you. main character energy, fr fr πŸ‘‘

class names are defined by table names and the namespace option, and here's the little chart so you can see it:

  +-----------+-----------+-----------+
  |   table   | namespace | class     |
  +-----------+-----------+-----------+
  |   foo     | Data      | Data::Foo |
  |   foo_bar |           | FooBar    |
  +-----------+-----------+-----------+

Class::DBI::Loader supports MySQL, Postgres and SQLite 🌈

also go see Class::DBI::Loader::Generic.


πŸ’… METHODS πŸ’…

new %args

all the little knobs and dials, bestie:

  • additional_base_classes β€” a list of extra base classes your table classes are gonna use.
  • left_base_classes β€” a list of extra base classes that need to be leftmost, for example Class::DBI::Sweet (the former Catalyst::Model::CDBI::Sweet).
  • additional_classes β€” a list of extra classes that your table classes will use.
  • constraint β€” only load tables matching this regex πŸ”
  • exclude β€” exclude tables matching this regex 🚫
  • debug β€” turn on debug messages.
  • dsn β€” the DBI Data Source Name.
  • namespace β€” the namespace under which your table classes get initialized.
  • password β€” password. (yeah. that's it. that's the description πŸ™ˆ)
  • options β€” optional hashref to specify DBI connect options.
  • relationships β€” try to automatically detect/set up has_a and has_many relationships 🫢
  • inflect β€” a hashref containing exceptions to Lingua::EN::Inflect::PL(). super useful for foreign language column names.
  • user β€” username.
  • require β€” attempt to require the dynamically defined module, so that extensions defined in files work. by default, errors from imported modules are suppressed. when you wanna debug, use require_warn.
  • require_warn β€” warn about import errors when requiring modules. πŸ“£

πŸ‘‘ AUTHOR πŸ‘‘

Daisuke Maki <dmaki@cpan.org>

AUTHOR EMERITUS

Sebastian Riedel, <sri@oook.de> β€” IKEBE Tomohiro, <ikebe@edge.co.jp>


πŸ’– THANK YOU πŸ’–

Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, Randal Schwartz, Simon Flack and all the others who've helped. absolute legends, every single one 🌟


πŸŽ€ LICENSE πŸŽ€

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


🌈 SEE ALSO 🌈

Class::DBI, Class::DBI::mysql, Class::DBI::Pg, Class::DBI::SQLite, Class::DBI::Loader::Generic, Class::DBI::Loader::mysql, Class::DBI::Loader::Pg, Class::DBI::Loader::SQLite


okay that's the whole page bestie, go forth and load some tables πŸ’…βœ¨ this lil manual is perl v5.36.0, dated 2022-12-07, and it's filed under Class:...Loader(3pm) β€” mwah, periodt πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from