Cataly...l::DBI(3pm)

πŸ“¦
version 0.32 Β· 2 versions
  • 0.32 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.32 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Catalyst::Model::DBI β€” the vibe ✨

okay bestie, welcome to Catalyst::Model::DBI(3pm) β€” yes that's the real manual name, she's a little long but she SERVES πŸ’… this is the DBI model class for Catalyst and she's been through a glow-up, so let's get into it 🫢


✨ NAME ✨

Catalyst::Model::DBI β€” the DBI Model Class, periodt πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

here's the whole situation, bestie β€” copy it exactly, don't freestyle it πŸ™ˆ

  # use the helper to create a model for example
  perl script/myapp_create.pl model MyModel DBI dsn username password

  # lib/MyApp/Model/DBI.pm
  package MyApp::Model::DBI;

  use base 'Catalyst::Model::DBI';

  __PACKAGE__->config(
    dsn           => 'DBI:Pg:dbname=mydb;host=localhost',
    username      => 'pgsql',
    password      => '',
    options       => { AutoCommit => 1 },
    loglevel      => 1
  );

  1;

  # or load settings from a config file via Config::General for example
  # in your myapp.conf you could have

  name MyApp

  <Model::MyModel>
    dsn "DBI:Pg:dbname=mydb;host=localhost"
    username pgsql
    password ""
    <options>
      AutoCommit 1
    </options>
    loglevel 1
  </Model>

  # note that config settings always override Model settings

  # do something with $dbh inside a controller ...
  my $dbh = $c->model('MyModel')->dbh;

  # do something with $dbh inside a model ...
  my $dbh = $self->dbh;

  #do something with DBIx::Connector connection inside a controller ...
  my $connection = $c->model('MyModel')->connection;

  #do something with DBIx::Connector connection inside a model ...
  my $connection = $self->connection;
important little note bestie: config settings always override Model settings. always. no cap. πŸ”₯

πŸ¦‹ DESCRIPTION πŸ¦‹

so this is the "DBI" model class, and the tea is that she got rewritten to use DBIx::Connector β€” because the internal code that deals with connection maintenance has already been ported into there. iconic behavior honestly πŸ‘‘

which means you now have two options for doing custom models with Catalyst:

  1. use this model and any related modules as needed, or
  2. have your custom model decoupled from Catalyst and glued on using Catalyst::Model::Adaptor

and here are the general rules, bestie, pay attention πŸ“:

  • if you do not wish to use DBIx::Connector directly or DBI and set up connections in your custom models, or if you have glue models β†’ use this model πŸ’š
  • if you however need models that can be re-used outside of your application, or you simply wish to maintain connection code yourself outside of the Catalyst β†’ use Catalyst::Model::Adaptor, which lets you glue outside models into your Catalyst app ✨

πŸ’… METHODS πŸ’…

  • new β€” initializes the DBI connection 🫢

$self->connection

returns the current DBIx::Connector connection handle 🌈

$self->dbh

returns the current database handle πŸ’–

$self->connect

connects to the database and returns the handle ⭐


🌸 SEE ALSO 🌸

go look at these too bestie, they're all part of the family:

  • Catalyst
  • DBI
  • Catalyst::Model::Proxy
  • Catalyst::Model::DBI::SQL::Library

πŸ‘‘ AUTHOR πŸ‘‘

Alex Pavlovic, "alex.pavlovic@taskforce-1.com" β€” thank you for your service 🫑✨


Copyright (c) 2005 - 2012 the Catalyst::Model::DBI "AUTHOR" as listed above.


πŸ’œ LICENSE πŸ’œ

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


and that's the whole page, bestie!! this was Cataly...l::DBI(3pm) from perl v5.34.0, dated 2022-06-09 β€” mwah, love u, go write some slay models πŸ’–πŸ¦‹πŸŽ€πŸ’…

πŸ“¦ where this page comes from