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