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