ok... apologies for yet another Catalyst doubt but I'm actually learning stuff these days... so, you know.

Anyways, I'm trying to connect to multiple databases depending on the user, for example: if user_1 logs in to my application, db_user_1_id should be automatically selected. Also, if a new user signs-up with my application, I'll create a model on the fly . To do this, I've taken the following approach, is there a better way?

My approach

1. If a new user signs-up, run a script (a bash or Perl script) that creates a MySql database for the new user. I'll call this new database DB_new_user. Now, I run another script that creates a model using the catalyst's helper script like:

$ script/myapp_create.pl model DB_new_user's_id DBIC::Schema myapp::Schema create=static dbi:mysql:DB_new_user '<Mysql username>' '<Mysql password>'

2. If an existing user (I'll call this user, user_n) logs in, a catalyst controller (say, `messages') can then select a specific database by saying:

sub messages :Local { my($self, $c) = @_; # somehow fetch user_n's id $c->stash(messages => [$c->model('DB_user_n::Messages')->all]); }

The codes shown are not necessarily correct, they are just an abstraction of what I'm doing/trying to achieve. :)

Update Just going through the Catalyst book again and it does say: If you need to use a different database, you can change the connection information in one file, restart your application, and the change will take effect everywhere, automatically.

No way... I love the concept of TIMTOWTDI in Perl. Still working on this.

In reply to Multiple Databases in Catalyst by code-ninja

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.