List Info

Thread: C::M::DBIC::Schema external configuration




C::M::DBIC::Schema external configuration
country flaguser name
Germany
2007-05-31 09:09:31
Hello There!

I've got a (hopefully) quite easy question 

If i wanted to have my database connection information
seperated from the
code in my myApp.yml file for Catalyst::Model:BIC::Sch
ema, how would i
actually do that?

Of course i could do:

Model:
 MyDB:
  connect_info:
   - DSN
   - USER
   - PASSWORD

But actually i don't like it this way. Also i will have to
add the
AutoCommit => 1 stuff into the "userconfig"
(and obviously i don't want
such internals to be tweaked by a novice user).

I would prefer to have just three questionable parameters:
Databasename,
username and password? I tried in my myApp.yml file:

databaseconfig:
 username: blah
 password: foo
 databasename: bar

And then in my Model:
__PACKAGE__->config->->

but this actually doesn't work?

Anybody some idea to have this seperated from the code in a
way, even some
kind of dummy-webmaster could set the application up?

Thans in advance,
Sven



_______________________________________________
List: Catalystlists.rawmode.org
Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
Dev site: http://dev.catalyst.per
l.org/

Re: C::M::DBIC::Schema external configuration
country flaguser name
United Kingdom
2007-05-31 09:42:20
On Thu, May 31, 2007 at 04:09:31PM +0200, Sven Eppler
wrote:
> Hello There!
> 
> I've got a (hopefully) quite easy question 
> 
> If i wanted to have my database connection information
seperated from the
> code in my myApp.yml file for Catalyst::Model:BIC::Sch
ema, how would i
> actually do that?
> 
> Of course i could do:
> 
> Model:
>  MyDB:
>   connect_info:
>    - DSN
>    - USER
>    - PASSWORD
> 
> But actually i don't like it this way. Also i will have
to add the
> AutoCommit => 1 stuff into the
"userconfig" (and obviously i don't want
> such internals to be tweaked by a novice user).
> 
> I would prefer to have just three questionable
parameters: Databasename,
> username and password? I tried in my myApp.yml file:
> 
> databaseconfig:
>  username: blah
>  password: foo
>  databasename: bar

in MyApp.pm

sub finalize_config {
  my $app = shift;
  $app->next::method(_);
  $app->config('Model:B' =>
{
    connect_info => [
     
'dbi:mysql:dbname='.$app->config->{dat
abasename},
      $app->config->,
      $app->config->,
      { AutoCommit => 1 }
    ]
  });
}

or similar depending on your DBD etc.

-- 
      Matt S Trout       Need help with your Catalyst or
DBIx::Class project?
   Technical Director    Want a managed development or
deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at)
shadowcatsystems.co.uk for a quote
http://chainsawblues.vo
x.com/             http://www.shadowc
atsystems.co.uk/ 

_______________________________________________
List: Catalystlists.rawmode.org
Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
Dev site: http://dev.catalyst.per
l.org/

Re: C::M::DBIC::Schema external configuration
user name
2007-05-31 09:48:59
Sven,

Seems to me this would work well as a plugin (C::P:BConnect
or?) with
the a setup method to "push" your global
"databaseconfig" options into
the appropriate config option for each model.

Something like...

package Catalyst::Plugin:BConnect
or;

sub setup {
    my $c = shift;

    foreach my $model ($c->models) {
       
$c->config->->{$model}-> =
$c->get_databaseconfig()
    }

}

1;

Of course, you've need to write the get_databaseconfig()
method to
extrapolate your "databaseconfig" into a structure
compatible with
connect_info.

Have fun.

-matt pitts

On Thu, 2007-05-31 at 16:09 +0200, Sven Eppler wrote:
> Hello There!
> 
> I've got a (hopefully) quite easy question 
> 
> If i wanted to have my database connection information
seperated from the
> code in my myApp.yml file for Catalyst::Model:BIC::Sch
ema, how would i
> actually do that?
> 
> Of course i could do:
> 
> Model:
>  MyDB:
>   connect_info:
>    - DSN
>    - USER
>    - PASSWORD
> 
> But actually i don't like it this way. Also i will have
to add the
> AutoCommit => 1 stuff into the
"userconfig" (and obviously i don't want
> such internals to be tweaked by a novice user).
> 
> I would prefer to have just three questionable
parameters: Databasename,
> username and password? I tried in my myApp.yml file:
> 
> databaseconfig:
>  username: blah
>  password: foo
>  databasename: bar
> 
> And then in my Model:
>
__PACKAGE__->config->->
> 
> but this actually doesn't work?
> 
> Anybody some idea to have this seperated from the code
in a way, even some
> kind of dummy-webmaster could set the application up?
> 
> Thans in advance,
> Sven
> 
> 
> 
> _______________________________________________
> List: Catalystlists.rawmode.org
> Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
> Dev site: http://dev.catalyst.per
l.org/
-- 
Matthew Pitts <mpittsa3its.com>
A3 IT Solutions, LLC

_______________________________________________
List: Catalystlists.rawmode.org
Listinfo: ht
tp://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-
archive.com/catalystlists.rawmode.org/
Dev site: http://dev.catalyst.per
l.org/

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )