File Coverage

blib/lib/DBIx/Class/Row/SQLA2Support.pm
Criterion Covered Total %
statement 24 24 100.0
branch 6 6 100.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1             package DBIx::Class::Row::SQLA2Support;
2 4     4   377504 use strict;
  4         14  
  4         120  
3 4     4   30 use warnings;
  4         18  
  4         106  
4 4     4   32 use parent 'DBIx::Class::Row';
  4         22  
  4         36  
5              
6             sub new {
7 3     3 1 28965 my ($class, $attrs) = @_;
8 3         11 my $on_conflict = delete $attrs->{-on_conflict};
9 3 100       29 my $to_upsert = 1 if delete $attrs->{-upsert};
10 3         17 my $new = $class->next::method($attrs);
11 3 100       414 $new->{_sqla2_attrs} = { on_conflict => $on_conflict } if defined $on_conflict;
12 3 100       14 if ($to_upsert) {
13 1         12 $to_upsert = {%$attrs};
14 1         7 my @pks = $new->result_source->primary_columns;
15 1         21 delete @$to_upsert{@pks};
16             $new->{_sqla2_attrs}
17             = {
18 1         14 on_conflict => { -target => \@pks, -set => { map +($_ => { -ident => "excluded.$_" }), keys %$to_upsert } } };
19             }
20              
21 3         15 return $new;
22             }
23              
24             sub insert {
25 3     3 1 83 my ($self, @args) = @_;
26 3         11 my $extras = delete $self->{_sqla2_attrs};
27             # this should allow relations to fail if they don't have a on_conflict defined
28 3         15 local $self->result_source->storage->sql_maker->{_sqla2_insert_attrs} = $extras;
29 3         375 $self->next::method(@args);
30             }
31              
32             1