Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Catalyst and DBI

by trwww (Priest)
on Jul 04, 2011 at 18:58 UTC ( #912686=note: print w/replies, xml ) Need Help??

in reply to Catalyst and DBI

How did you create your model? I ask because if you're having to add in connection info for each model class then you're doing it wrong. You only need to set the database configuration in one place. See:


Replies are listed 'Best First'.
Re^2: Catalyst and DBI
by Uragan (Initiate) on Jul 04, 2011 at 20:41 UTC

    I don't use DBIx. I use Catalyst::Model::DBI. When I create a model, I write next:

    ./ model Name_of_Model DBI:mysql:auth username password

    In this case dsn, username and password pass into the model configuration. So each model has it's own configuration (the same). Without this configuration model can not connect to database. I use DBI, because I must write live queries without any ORM. I now thar it's wrong write configuration in every model and when every model connects to DB separately, but I can not understand, how I can do only one connection and write connection params in one place(((

      I use DBI, because I must write live queries without any ORM... But now every model has it's own connection...

      Do you need more than one DBI model per database, and if so, why?


      You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

        I've been working on some documentation for dbi models.

        • or

        You would create a single model to connect to each database. Then you would create submodels for each group of methods, I frequently group them by table.

        # Parent MODEL package BoPeep::Model::BoPeep; use strict; use warnings; use DBIx::Simple ; use parent 'Catalyst::Model::DBI'; __PACKAGE__->config( dsn => BoPeep->config->{dsn} , user => BoPeep->config->{user} , password => BoPeep->config->{password} , ); use Moose ; #use Moose immediately before calling #on Moose to extend the object has db=>( is =>'ro', isa=>'DBIx::Simple', lazy_build=> 1, # If we don't want to handle all dbis methods, # specify those that we want. # handles=> [qw/query flat /], ); sub _build_db { my $self = shift ; return DBIx::Simple->connect($self->dbh); } ; # Child Model package BoPeep::Model::BoPeep::Flock; use Moose; use BoPeep; use namespace::autoclean; extends 'BoPeep::Model::BoPeep'; sub List { my $self = shift ; my $db = $self->db ; my @sheep = $db->query('SELECT * FROM flock')->flat ; return @sheep ; } __PACKAGE__->meta->make_immutable( inline_constructor => 0 ); 1;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://912686]
[Datz_cozee75]: sometimes I feel like a future friar, other times I feel the fryee

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2018-06-21 22:13 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.