kentnl / App-DH

Deploy your DBIx::Class Schema to DDL/Database via DBIx::Class::DeploymentHandler
Other
0 stars 1 forks source link

setting connection_name as DBIx::Class::Schema::Config alias #3

Closed p-alik closed 7 years ago

p-alik commented 7 years ago

could you explain how to set connection_name as DBIx::Class::Schema::Config alias, please. connection_name in example/subclass.pl looks like an alias but without MyApp::Schema I can't figure out how it's work.

kentfredric commented 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.

p-alik commented 7 years ago

thank you very much for detailed explanation, @kentfredric.

Here connection_name would be simply MY_DATABASE

It conforms to my assumption. I'll test it and reply to you.

p-alik commented 7 years ago

@kentfredric, thank your one more time. Indeed it works fine.