more cleanup stuff, standardized usage of dbh->get_info(29) (sql quote char)
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Pg.pm
1 package DBIx::Class::Schema::Loader::Pg;
2
3 use strict;
4 use base 'DBIx::Class::Schema::Loader::Generic';
5 use Carp;
6
7 =head1 NAME
8
9 DBIx::Class::Schema::Loader::Pg - DBIx::Class::Schema::Loader Postgres Implementation.
10
11 =head1 SYNOPSIS
12
13   use DBIx::Class::Schema::Loader;
14
15   # $loader is a DBIx::Class::Schema::Loader::Pg
16   my $loader = DBIx::Class::Schema::Loader->new(
17     dsn       => "dbi:Pg:dbname=dbname",
18     user      => "postgres",
19     password  => "",
20   );
21
22 =head1 DESCRIPTION
23
24 See L<DBIx::Class::Schema::Loader>.
25
26 =cut
27
28 sub _loader_db_classes {
29     return qw/DBIx::Class::PK::Auto::Pg/;
30 }
31
32 sub _loader_tables {
33     my $class = shift;
34     my $dbh = $class->storage->dbh;
35     my $quoter = $dbh->get_info(29) || q{"};
36
37     # This is split out to avoid version parsing errors...
38     my $is_dbd_pg_gte_131 = ( $DBD::Pg::VERSION >= 1.31 );
39     my @tables = $is_dbd_pg_gte_131
40         ?  $dbh->tables( undef, $class->_loader_data->{db_schema}, "",
41                          "table", { noprefix => 1, pg_noprefix => 1 } )
42         : $dbh->tables;
43
44     s/$quoter//g for @tables;
45     return @tables;
46 }
47
48 sub _loader_table_info {
49     my ( $class, $table ) = @_;
50     my $dbh = $class->storage->dbh;
51     my $quoter = $dbh->get_info(29) || q{"};
52
53     my $sth = $dbh->column_info(undef, $class->_loader_data->{db_schema}, $table, undef);
54     my @cols = map { $_->[3] } @{ $sth->fetchall_arrayref };
55     s/$quoter//g for @cols;
56     
57     my @primary = $dbh->primary_key(undef, $class->_loader_data->{db_schema}, $table);
58
59     s/$quoter//g for @primary;
60
61     return ( \@cols, \@primary );
62 }
63
64 =head1 SEE ALSO
65
66 L<DBIx::Class::Schema::Loader>
67
68 =cut
69
70 1;