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