| 1 | package Slick::DatabaseExecutor::Pg; | ||
| 2 | |||
| 3 | use 5.036; | ||
| 4 | |||
| 5 | use Moo; | ||
| 6 | use Carp qw(croak); | ||
| 7 | use DBI; | ||
| 8 | |||
| 9 | with 'Slick::DatabaseExecutor'; | ||
| 10 | |||
| 11 | sub BUILD { | ||
| 12 | my $self = shift; | ||
| 13 | |||
| 14 | my $db = ( split /\//x, $self->{connection}->path )[1]; | ||
| 15 | |||
| 16 | my $dsn = defined $db ? "dbi:Pg:dbname=$db" : "dbi:Pg"; | ||
| 17 | if ( my $host = $self->{connection}->host ) { $dsn .= ";host=$host"; } | ||
| 18 | if ( my $port = $self->{connection}->port ) { $dsn .= ";port=$port"; } | ||
| 19 | |||
| 20 | my ( $username, $password ) = | ||
| 21 | split /\:/x, [ split /\@/x, $self->{connection}->authority ]->[0]; | ||
| 22 | |||
| 23 | $self->{dbi} = DBI->connect( $dsn, $username // '', $password // '', | ||
| 24 | $self->dbi_options ); | ||
| 25 | |||
| 26 | croak qq{Couldn't connect to database: } . $self->{connection} | ||
| 27 | unless $self->dbi->ping; | ||
| 28 | |||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; | ||
| 33 | |||
| 34 | =encoding utf8 | ||
| 35 | |||
| 36 | =head1 NAME | ||
| 37 | |||
| 38 | Slick::DatabaseExecutor::Pg | ||
| 39 | |||
| 40 | =head1 SYNOPSIS | ||
| 41 | |||
| 42 | A child class of L<Slick::DatabaseExecutor>, handles all interactions with PostgreSQL, mostly just configuring the connection. | ||
| 43 | |||
| 44 | =head1 See also | ||
| 45 | |||
| 46 | =over 2 | ||
| 47 | |||
| 48 | =item * L<Slick> | ||
| 49 | |||
| 50 | =item * L<Slick::RouteManager> | ||
| 51 | |||
| 52 | =item * L<Slick::Context> | ||
| 53 | |||
| 54 | =item * L<Slick::Database> | ||
| 55 | |||
| 56 | =item * L<Slick::DatabaseExecutor> | ||
| 57 | |||
| 58 | =item * L<Slick::DatabaseExecutor::MySQL> | ||
| 59 | |||
| 60 | =item * L<Slick::EventHandler> | ||
| 61 | |||
| 62 | =item * L<Slick::Events> | ||
| 63 | |||
| 64 | =item * L<Slick::Methods> | ||
| 65 | |||
| 66 | =item * L<Slick::RouteMap> | ||
| 67 | |||
| 68 | =item * L<Slick::Util> | ||
| 69 | |||
| 70 | =back | ||
| 71 | |||
| 72 | =cut |