Added missing space in error message
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Pg.pm
CommitLineData
18fca96a 1package DBIx::Class::Schema::Loader::Pg;
a78e3fed 2
3use strict;
3980d69c 4use warnings;
2a4b8262 5use Class::C3;
18fca96a 6use base 'DBIx::Class::Schema::Loader::Generic';
a78e3fed 7
a78e3fed 8=head1 NAME
9
18fca96a 10DBIx::Class::Schema::Loader::Pg - DBIx::Class::Schema::Loader Postgres Implementation.
a78e3fed 11
12=head1 SYNOPSIS
13
457eb8a6 14 package My::Schema;
15 use base qw/DBIx::Class::Schema::Loader/;
a78e3fed 16
457eb8a6 17 __PACKAGE__->load_from_connection(
a78e3fed 18 dsn => "dbi:Pg:dbname=dbname",
19 user => "postgres",
20 password => "",
a78e3fed 21 );
a78e3fed 22
457eb8a6 23 1;
24
a78e3fed 25=head1 DESCRIPTION
26
18fca96a 27See L<DBIx::Class::Schema::Loader>.
a78e3fed 28
2a4b8262 29=head1 METHODS
30
457eb8a6 31=head2 new
2a4b8262 32
33Overrides L<DBIx::Class::Schema::Loader::Generic>'s C<new()> to default the postgres
34schema to C<public> rather than blank.
35
a78e3fed 36=cut
37
2a4b8262 38sub new {
39 my ($class, %args) = @_;
40
41 my $self = $class->next::method(%args);
42 $self->{db_schema} ||= 'public';
43
44 $self;
45}
46
3980d69c 47sub _db_classes {
9fa99683 48 return qw/PK::Auto::Pg/;
a78e3fed 49}
50
ac5ad557 51sub _tables_list {
3980d69c 52 my $self = shift;
53 my $dbh = $self->schema->storage->dbh;
b005807a 54 my $quoter = $dbh->get_info(29) || q{"};
a78e3fed 55
56 # This is split out to avoid version parsing errors...
57 my $is_dbd_pg_gte_131 = ( $DBD::Pg::VERSION >= 1.31 );
b005807a 58 my @tables = $is_dbd_pg_gte_131
3980d69c 59 ? $dbh->tables( undef, $self->db_schema, "",
b005807a 60 "table", { noprefix => 1, pg_noprefix => 1 } )
a78e3fed 61 : $dbh->tables;
62
b005807a 63 s/$quoter//g for @tables;
a78e3fed 64 return @tables;
65}
66
3980d69c 67sub _table_info {
68 my ( $self, $table ) = @_;
69 my $dbh = $self->schema->storage->dbh;
b005807a 70 my $quoter = $dbh->get_info(29) || q{"};
a78e3fed 71
3980d69c 72 my $sth = $dbh->column_info(undef, $self->db_schema, $table, undef);
ac5ad557 73 my @cols = map { lc $_->[3] } @{ $sth->fetchall_arrayref };
b005807a 74 s/$quoter//g for @cols;
a78e3fed 75
ac5ad557 76 my @primary = map { lc } $dbh->primary_key(undef, $self->db_schema, $table);
a78e3fed 77
b005807a 78 s/$quoter//g for @primary;
a78e3fed 79
80 return ( \@cols, \@primary );
81}
82
83=head1 SEE ALSO
84
18fca96a 85L<DBIx::Class::Schema::Loader>
a78e3fed 86
87=cut
88
891;