Schema::Loader converted to better inheritance model, no longer pollutes user schema...
[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;
18fca96a 5use base 'DBIx::Class::Schema::Loader::Generic';
a78e3fed 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
3980d69c 28sub _db_classes {
a78e3fed 29 return qw/DBIx::Class::PK::Auto::Pg/;
30}
31
3980d69c 32sub _tables {
33 my $self = shift;
34 my $dbh = $self->schema->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
3980d69c 40 ? $dbh->tables( undef, $self->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
3980d69c 48sub _table_info {
49 my ( $self, $table ) = @_;
50 my $dbh = $self->schema->storage->dbh;
b005807a 51 my $quoter = $dbh->get_info(29) || q{"};
a78e3fed 52
3980d69c 53 my $sth = $dbh->column_info(undef, $self->db_schema, $table, undef);
a78e3fed 54 my @cols = map { $_->[3] } @{ $sth->fetchall_arrayref };
b005807a 55 s/$quoter//g for @cols;
a78e3fed 56
3980d69c 57 my @primary = $dbh->primary_key(undef, $self->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;