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