Commit | Line | Data |
18fca96a |
1 | package DBIx::Class::Schema::Loader::Pg; |
a78e3fed |
2 | |
3 | use strict; |
3980d69c |
4 | use warnings; |
18fca96a |
5 | use base 'DBIx::Class::Schema::Loader::Generic'; |
a78e3fed |
6 | |
a78e3fed |
7 | =head1 NAME |
8 | |
18fca96a |
9 | DBIx::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 |
24 | See L<DBIx::Class::Schema::Loader>. |
a78e3fed |
25 | |
26 | =cut |
27 | |
3980d69c |
28 | sub _db_classes { |
a78e3fed |
29 | return qw/DBIx::Class::PK::Auto::Pg/; |
30 | } |
31 | |
3980d69c |
32 | sub _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 |
48 | sub _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 |
66 | L<DBIx::Class::Schema::Loader> |
a78e3fed |
67 | |
68 | =cut |
69 | |
70 | 1; |