[Catalyst] connection info and Catalyst::Model::DBIC::Schema
Brandon Black
blblack at gmail.com
Thu Aug 3 22:02:14 CEST 2006
On 8/3/06, Alan Humphrey <alan.humphrey at comcast.net> wrote:
>
> I feel that I'm missing something obvious, but the penny hasn't dropped.
> Hope you all can help.
>
> Goal: use a DBIx::Class schema defined outside the Catalyst app name
> space.
This is what I do, perhaps someone can make the solution easier and more
general and/or write up some docs about it:
1) My Schema is at MyApp::Schema. It doesn't contain any connection info
2) My Model is at MyCatApp::Model::MyModel. The only useful statements in
there are:
__PACKAG__->config( schema_class => 'MyApp::Schema' );
3) My actual database connect info is in a seperate external config file,
lets say a YAML file, but not your main Catalyst YAML config file.
4) I make a package called MyApp::Site, which loads all of the information
in the above YAML file (which is site-specific config data for my whole
application, where Catalyst is just one component of that), and makes it
available in the hashref $MyApp::Site::Config
5) In external tools, I do:
use MyApp::Site;
use MyApp::Schema;
my $schema =
MyApp::Schema->connect($MyApp::Site::Config->{db_connect_info});
...
6) In lib/MyCatApp.pm (the main file for the cat app), I do ..
use MyApp::Site;
[.... usual Cat app stuff, including config loading for cat-specific
parameters from wherever as usual... ]
__PACKAGE__->config->{Model::MyModel}->{connect_info} =
$MyApp::Site::Config->{db_connect_info};
__PACKAGE__->setup();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060803/eda3877a/attachment.htm
More information about the Catalyst
mailing list