Closed p-alik closed 7 years ago
connection_name
takes any legal DSN string, so if you didn't have DBIx::Class::Schema::Config, you'd just pass a standard DSN.
DBIx::Class::Schema::Config provides a bit of magical glue which allows defining common names for DSN connections:
For instance, in the example on DBIx::Class::Schema::Config
# /etc/dbic.yaml
---
MY_DATABASE:
dsn: "dbi:Pg:host=localhost;database=blog"
user: "TheDoctor"
password: "dnoPydoleM"
TraceLevel: 1
package My::Schema
use warnings;
use strict;
use base 'DBIx::Class::Schema::Config';
__PACKAGE__->load_namespaces;
package My::Code;
use warnings;
use strict;
use My::Schema;
my $schema = My::Schema->connect('MY_DATABASE');
# arbitrary config access from anywhere in your $app
my $level = My::Schema->config->{TraceLevel};
Here connection_name
would be simply MY_DATABASE
That is to say, connection_name
is not a property defined anywhere in MyApp::Schema
, its defined in your global configuration by DBIx::Class::Schema::Config
, and is subsequently a global alias.
thank you very much for detailed explanation, @kentfredric.
Here
connection_name
would be simplyMY_DATABASE
It conforms to my assumption. I'll test it and reply to you.
@kentfredric, thank your one more time. Indeed it works fine.
could you explain how to set
connection_name
asDBIx::Class::Schema::Config
alias, please.connection_name
in example/subclass.pl looks like an alias but withoutMyApp::Schema
I can't figure out how it's work.