Commit | Line | Data |
843f8ecd |
1 | package DBIx::Class::Storage::DBI::Pg; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use base qw/DBIx::Class::Storage::DBI/; |
7 | |
8 | # __PACKAGE__->load_components(qw/PK::Auto/); |
9 | |
10 | sub last_insert_id { |
ca48cd7d |
11 | my ($self,$source,$col) = @_; |
12 | my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col)); |
13 | $self->_dbh->last_insert_id(undef,undef,undef,undef, {sequence => $seq}); |
843f8ecd |
14 | } |
15 | |
16 | sub get_autoinc_seq { |
ca48cd7d |
17 | my ($self,$source,$col) = @_; |
18 | |
843f8ecd |
19 | my @pri = $source->primary_columns; |
20 | my $dbh = $self->_dbh; |
34470972 |
21 | my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2) |
22 | : (undef,$source->name); |
843f8ecd |
23 | while (my $col = shift @pri) { |
24 | my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_arrayref; |
75d07914 |
25 | if (defined $info->[12] and $info->[12] =~ |
32da1042 |
26 | /^nextval\(+'([^']+)'::(?:text|regclass)\)/) |
843f8ecd |
27 | { |
644b02f7 |
28 | return $1; # may need to strip quotes -- see if this works |
75d07914 |
29 | } |
843f8ecd |
30 | } |
31 | } |
32 | |
4f533e8c |
33 | sub sqlt_type { |
34 | return 'PostgreSQL'; |
35 | } |
36 | |
843f8ecd |
37 | 1; |
38 | |
75d07914 |
39 | =head1 NAME |
843f8ecd |
40 | |
41 | DBIx::Class::Storage::DBI::Pg - Automatic primary key class for PostgreSQL |
42 | |
43 | =head1 SYNOPSIS |
44 | |
45 | # In your table classes |
46 | __PACKAGE__->load_components(qw/PK::Auto Core/); |
47 | __PACKAGE__->set_primary_key('id'); |
48 | __PACKAGE__->sequence('mysequence'); |
49 | |
50 | =head1 DESCRIPTION |
51 | |
52 | This class implements autoincrements for PostgreSQL. |
53 | |
54 | =head1 AUTHORS |
55 | |
56 | Marcus Ramberg <m.ramberg@cpan.org> |
57 | |
58 | =head1 LICENSE |
59 | |
60 | You may distribute this code under the same terms as Perl itself. |
61 | |
62 | =cut |