update proxied methods for DBI::Replicated
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / InsertReturning.pm
CommitLineData
be860760 1package DBIx::Class::Storage::DBI::InsertReturning;
2
3use strict;
4use warnings;
5
6use base qw/DBIx::Class::Storage::DBI/;
7use mro 'c3';
8
be860760 9=head1 NAME
10
11DBIx::Class::Storage::DBI::InsertReturning - Storage component for RDBMSes
12supporting INSERT ... RETURNING
13
14=head1 DESCRIPTION
15
16Provides Auto-PK and
17L<is_auto_increment|DBIx::Class::ResultSource/is_auto_increment> support for
1e45aa87 18databases supporting the C<INSERT ... RETURNING> syntax.
be860760 19
20=cut
21
1e45aa87 22sub insert {
be860760 23 my $self = shift;
1e45aa87 24 my ($source, $to_insert, $opts) = @_;
be860760 25
1e45aa87 26 return $self->next::method (@_) unless ($opts && $opts->{returning});
be860760 27
1e45aa87 28 my $updated_cols = $self->_prefetch_insert_auto_nextvals ($source, $to_insert);
be860760 29
1e45aa87 30 my $bind_attributes = $self->source_bind_attributes($source);
31 my ($rv, $sth) = $self->_execute (insert => [], $source, $bind_attributes, $to_insert, $opts);
be860760 32
1e45aa87 33 if (my @ret_cols = @{$opts->{returning}}) {
be860760 34
1e45aa87 35 my @ret_vals = eval {
be860760 36 local $SIG{__WARN__} = sub {};
1e45aa87 37 my @r = $sth->fetchrow_array;
38 $sth->finish;
39 @r;
be860760 40 };
be860760 41
1e45aa87 42 my %ret;
43 @ret{@ret_cols} = @ret_vals if (@ret_vals);
be860760 44
1e45aa87 45 $updated_cols = {
46 %$updated_cols,
47 %ret,
48 };
be860760 49 }
50
51 return $updated_cols;
52}
53
be860760 54=head1 AUTHOR
55
56See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>
57
58=head1 LICENSE
59
60You may distribute this code under the same terms as Perl itself.
61
62=cut
63
641;