Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Catalyst and DBI

by Uragan (Initiate)
on Jul 04, 2011 at 06:50 UTC ( #912595=perlquestion: print w/replies, xml ) Need Help??

Uragan has asked for the wisdom of the Perl Monks concerning the following question:

Hi all! I use Catalyst and DBI. I want to connect my database only in one place. But now every model has it's own connection and I must write in config file params(dsn, username, password) for every model, like this:

<Model::Name_of_model> dsn DBI:mysql:name_of_database user username password user_password </Model::Name_of_Model>

I must do it for every model. Is it possible to do it only once and in one place? And that each model would take these params.

Replies are listed 'Best First'.
Re: Catalyst and DBI
by Anonymous Monk on Jul 04, 2011 at 06:56 UTC
Re: Catalyst and DBI
by trwww (Priest) on Jul 04, 2011 at 18:58 UTC

    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:

    Catalyst::Model::DBIC::Schema

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

      ./app_create.pl 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?

        --Solo

        --
        You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.
Re: Catalyst and DBI
by sundialsvc4 (Abbot) on Jul 04, 2011 at 12:50 UTC

    As an aside, not directly related to Catalyst but worth bringing up anyway, I recently “discovered” DBIx::Connector ...

    DBIx::Connector provides a simple interface for fast and safe DBI connection and transaction management.   Connecting to a database can be expensive; you don't want your application to re-connect every time you need to run a query.   The efficient thing to do is to hang on to a database handle to maintain a connection to the database in order to minimize that overhead.   DBIx::Connector lets you do that without having to worry about dropped or corrupted connections.”

    It made a very dramatic speed difference to the kludgy old app that I am busy rehabilitating, and stood up quite well to initial stress-tests.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://912595]
Approved by davies
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-07-04 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?