various identifier cleanups, to help prevent clashing with Schema stuff down the...
[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
36     # This is split out to avoid version parsing errors...
37     my $is_dbd_pg_gte_131 = ( $DBD::Pg::VERSION >= 1.31 );
38     my @tables = $is_dbd_pg_gte_131 ? 
39         $dbh->tables( undef, $class->_loader_data->{db_schema}, "", "table", { noprefix => 1, pg_noprefix => 1 } )
40         : $dbh->tables;
41
42     s/"//g for @tables;
43     return @tables;
44 }
45
46 sub _loader_table_info {
47     my ( $class, $table ) = @_;
48     my $dbh = $class->storage->dbh;
49
50     my $sth = $dbh->column_info(undef, $class->_loader_data->{db_schema}, $table, undef);
51     my @cols = map { $_->[3] } @{ $sth->fetchall_arrayref };
52     s/"//g for @cols;
53     
54     my @primary = $dbh->primary_key(undef, $class->_loader_data->{db_schema}, $table);
55
56     s/"//g for @primary;
57
58     return ( \@cols, \@primary );
59 }
60
61 =head1 SEE ALSO
62
63 L<DBIx::Class::Schema::Loader>
64
65 =cut
66
67 1;