1 |
package Strix; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use base qw/Jifty::Object/; |
7 |
|
8 |
use DBI; |
9 |
use Data::Dump qw/dump/; |
10 |
|
11 |
=head1 NAME |
12 |
|
13 |
Strix |
14 |
|
15 |
=head1 METHODS |
16 |
|
17 |
=head2 dbh |
18 |
|
19 |
my $dbh = Strix->dbh( $site_name ); |
20 |
|
21 |
=cut |
22 |
|
23 |
sub dbh { |
24 |
my $self = shift; |
25 |
|
26 |
my $site = shift or die "no site?"; |
27 |
|
28 |
my $config = Jifty->config->app('strix') or die "need strix config"; |
29 |
my $database = $config->{database} or die "no strix.database in config"; |
30 |
|
31 |
Jifty->log->debug("using config ", dump( $database )); |
32 |
|
33 |
my $dsn = |
34 |
'DBI:Pg:dbname=' . $site . |
35 |
';host=' . $database->{host} . |
36 |
';port=' . $database->{port}; |
37 |
|
38 |
Jifty->log->info("Connect to site $site with dsn $dsn"); |
39 |
|
40 |
my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr; |
41 |
|
42 |
return $dbh; |
43 |
} |
44 |
|
45 |
1; |