diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-03-01 15:43:03 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-03-01 15:43:03 +0000 |
commit | 69dc1b4f49e1d3f596828065aa77f510366f454f (patch) | |
tree | 3f4f6bdee3a0336577d3c19962522c89f8fa862c /perllib/FixMyStreet.pm | |
parent | 66e1bcb493c12547f5f41cf8738d03148d3f12e8 (diff) |
Added method to return DB connection info
Diffstat (limited to 'perllib/FixMyStreet.pm')
-rw-r--r-- | perllib/FixMyStreet.pm | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm index daa9de334..645780629 100644 --- a/perllib/FixMyStreet.pm +++ b/perllib/FixMyStreet.pm @@ -62,4 +62,42 @@ sub config { return exists $CONFIG{$key} ? $CONFIG{$key} : undef; } +=head2 dbic_connect_info + + $connect_info = FixMyStreet->dbic_connect_info(); + +Returns the array that DBIx::Class::Schema needs to connect to the database. +Most of the values are read from the config file and others are hordcoded here. + +=cut + +# for exact details on what this could return refer to: +# +# http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Storage/DBI.pm#connect_info +# +# we use the one that is most similar to DBI's connect. + +sub dbic_connect_info { + my $class = shift; + my $config = $class->config; + + my $dsn = "dbi:Pg:dbname=" . $config->{BCI_DB_NAME}; + $dsn .= ";host=$config->{BCI_DB_HOST}" + if $config->{BCI_DB_HOST}; + $dsn .= ";port=$config->{BCI_DB_PORT}" + if $config->{BCI_DB_PORT}; + $dsn .= ";sslmode=allow"; + + my $user = $config->{BCI_DB_USER} || undef; + my $password = $config->{BCI_DB_PASS} || undef; + + my $dbi_args = { + AutoCommit => 1, + pg_enable_utf8 => 1, + }; + my $dbic_args = {}; + + return [ $dsn, $user, $password, $dbi_args, $dbic_args ]; +} + 1; |