| 1 | package DBIx::Class::Row::SQLA2Support; | ||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use parent 'DBIx::Class::Row'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | sub new { | ||||||||||
| 7 | 3 | ▶ | my ($class, $attrs) = @_; | ||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 8 | 3 | my $on_conflict = delete $attrs->{-on_conflict}; | |||||||||
| 9 | 3 | ▶ | my $to_upsert = 1 if delete $attrs->{-upsert}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 10 | 3 | my $new = $class->next::method($attrs); | |||||||||
| 11 | 3 | ▶ | $new->{_sqla2_attrs} = { on_conflict => $on_conflict } if defined $on_conflict; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 3 | ▶ | if ($to_upsert) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 1 | $to_upsert = {%$attrs}; | |||||||||
| 14 | 1 | my @pks = $new->result_source->primary_columns; | |||||||||
| 15 | 1 | delete @$to_upsert{@pks}; | |||||||||
| 16 | $new->{_sqla2_attrs} | ||||||||||
| 17 | = { | ||||||||||
| 18 | 1 | on_conflict => { -target => \@pks, -set => { map +($_ => { -ident => "excluded.$_" }), keys %$to_upsert } } }; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 3 | return $new; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub insert { | ||||||||||
| 25 | 3 | ▶ | my ($self, @args) = @_; | ||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | 3 | my $extras = delete $self->{_sqla2_attrs}; | |||||||||
| 27 | # this should allow relations to fail if they don't have a on_conflict defined | ||||||||||
| 28 | 3 | local $self->result_source->storage->sql_maker->{_sqla2_insert_attrs} = $extras; | |||||||||
| 29 | 3 | $self->next::method(@args); | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 5 | 1 | |||||||||