[Dbix-class] Passing in the database connection data
Krzysztof Krzyzaniak
eloy at kofeina.net
Mon Dec 12 12:52:09 CET 2005
Nigel Metheringham wrote:
> I'd like to get a few suggestions as to the best practice for handling
> this...
>
> I have a set of DBIC classes relating to a single database - these all
> are based on a parent class which currently has a hard coded DB
> connection data:-
> __PACKAGE__->load_components(qw/WebForm PK::Auto::SQLite Core DB/);
> __PACKAGE__->connection(
> 'dbi:SQLite:/home/nigel/src/project/db/feature.db',
> '', '',
> {
> RaiseError => 1,
> PrintError => 0,
> ShowErrorStatement => 1,
> TraceLevel => 0,
> }
> );
>
> This set of classes are used by 2 sets of applications - a Catalyst
> based app, and a set of data collection scripts which interact with the
> database but do not have any Catalyst magic involved.
>
> I'd like to be able to parametrise the database connection info being
> used (eg the experimental one on my laptop is likely to stay as a
> sqlite, the production and test will be PgSQL).
>
> Any suggestions as to good ways of pushing the connection data into this
> would be appreciated - I am considering using a YAML config file for the
> Catalyst side, and would be very open to doing that for the other
> scripts too.
YAML will do the job:
....
use FindBind
my $config = YAML::LoadFile($FindBin::Bin.'/../databases.yml');
....
_PACKAGE__->connection (
$config->{'dsn'},
$config->{'user'},
$config->{'pass'},
{ RaiseError => 1, PrintError => 0, ShowErrorStatement => 1,
TraceLevel => 0
}
);
--
-------e-l-o-y---------------------------e-l-o-y- at -k-o-f-e-i-n-a-.-n-e-t------
jak to dobrze, że są oceany - bez nich byłoby jeszcze smutniej
More information about the Dbix-class
mailing list