1 package DBIx::Class::Storage::DBI::Pg;
6 use base qw/DBIx::Class::Storage::DBI/;
8 # __PACKAGE__->load_components(qw/PK::Auto/);
11 my ($self, $source) = @_;
12 $self->get_autoinc_seq($source) unless $source->{_autoinc_seq};
13 $self->_dbh->last_insert_id(undef,undef,undef,undef,
14 {sequence => $source->{_autoinc_seq}});
18 my ($self,$source) = @_;
20 # return the user-defined sequence if known
21 my $result_class = $source->result_class;
22 if ($result_class->can('sequence') and $result_class->sequence) {
23 return ($source->{_autoinc_seq} = $result_class->sequence);
26 my @pri = $source->primary_columns;
27 my $dbh = $self->_dbh;
28 my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2)
29 : (undef,$source->name);
30 while (my $col = shift @pri) {
31 my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_arrayref;
32 if (defined $info->[12] and $info->[12] =~
33 /^nextval\('"?([^"']+)"?'::(?:text|regclass)\)/)
35 $source->{_autoinc_seq} = $1;
45 DBIx::Class::Storage::DBI::Pg - Automatic primary key class for PostgreSQL
49 # In your table classes
50 __PACKAGE__->load_components(qw/PK::Auto Core/);
51 __PACKAGE__->set_primary_key('id');
52 __PACKAGE__->sequence('mysequence');
56 This class implements autoincrements for PostgreSQL.
60 Marcus Ramberg <m.ramberg@cpan.org>
64 You may distribute this code under the same terms as Perl itself.