1 package DBIx::Class::PK::Auto::Pg;
6 use base qw/DBIx::Class/;
8 __PACKAGE__->load_components(qw/PK::Auto/);
12 $self->get_autoinc_seq unless $self->{_autoinc_seq};
13 $self->result_source->storage->dbh->last_insert_id(undef,undef,undef,undef,
14 {sequence=>$self->{_autoinc_seq}});
20 # return the user-defined sequence if known
21 if ($self->sequence) {
22 return $self->{_autoinc_seq} = $self->sequence;
25 my @pri = $self->primary_columns;
26 my $dbh = $self->result_source->storage->dbh;
27 while (my $col = shift @pri) {
28 my $info = $dbh->column_info(undef,undef,$self->table,$col)->fetchrow_arrayref;
29 if (defined $info->[12] and $info->[12] =~
30 /^nextval\('"?([^"']+)"?'::(?:text|regclass)\)/)
32 $self->{_autoinc_seq} = $1;
42 DBIx::Class::PK::Auto::Pg - Automatic primary key class for PostgreSQL
46 # In your table classes
47 __PACKAGE__->load_components(qw/PK::Auto::Pg Core/);
48 __PACKAGE__->set_primary_key('id');
52 This class implements autoincrements for PostgreSQL.
56 Marcus Ramberg <m.ramberg@cpan.org>
60 You may distribute this code under the same terms as Perl itself.