|Perl Monk, Perl Meditation|
Multiple Databases in Catalystby code-ninja (Scribe)
|on May 11, 2013 at 07:42 UTC||Need Help??|
code-ninja has asked for the
wisdom of the Perl Monks concerning the following question:
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?
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:
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:
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.