| 1 | package DBIx::Class::SQLA2; | ||||||||||||||||||||||||||||
| 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 feature 'postderef'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | no warnings 'experimental::postderef'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | use base qw( | |||||||||||||||||||||||||||
| 9 | DBIx::Class::SQLMaker::ClassicExtensions | ||||||||||||||||||||||||||||
| 10 | SQL::Abstract | ||||||||||||||||||||||||||||
| 11 | SQL::Abstract::Classic | ||||||||||||||||||||||||||||
| 12 | 5 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | __PACKAGE__->mk_group_accessors(simple => '_connection_info'); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub _render_hashrefrefs { | ||||||||||||||||||||||||||||
| 19 | 5 | ▶ | my ($self, $list) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_render_hashrefrefs: called CC=5 SCAR=17.5
| |||||||||||||||||||||||||||||
| 20 | 5 | ▶ | my @fields = ref $list eq 'ARRAY' ? @$list : $list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | return [ | ||||||||||||||||||||||||||||
| 22 | map { | ||||||||||||||||||||||||||||
| 23 | 5 | ref $_ eq 'REF' && ref $$_ eq 'HASH' | |||||||||||||||||||||||||||
| 24 | 5 | ▶ | ? do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_ eq "REF" and ref $$_ eq "HASH"
MC/DC0%0/2
ref $_ eq "REF" and ref $$_ eq "HASH"
ref $_ eq "REF"
ref $$_ eq "HASH"
Truth table33%1/3
A and B
A= ref $_ eq "REF"B= ref $$_ eq "HASH"
| |||||||||||||||||||||||||||||
| 25 | 5 | my %f = $$_->%*; | |||||||||||||||||||||||||||
| 26 | 5 | my $as = delete $f{-as}; | |||||||||||||||||||||||||||
| 27 | \[ | ||||||||||||||||||||||||||||
| 28 | 5 | ▶ | $as | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | ? $self->render_expr({ -op => [ 'as', \%f, { -ident => $as } ] }) | ||||||||||||||||||||||||||||
| 30 | : $self->render_expr(\%f) | ||||||||||||||||||||||||||||
| 31 | ]; | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | : $_ | ||||||||||||||||||||||||||||
| 34 | } @fields | ||||||||||||||||||||||||||||
| 35 | ]; | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub _recurse_fields { | ||||||||||||||||||||||||||||
| 39 | 111 | ▶ | my ($self, $fields) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_recurse_fields: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 40 | 111 | ▶ | if (ref $fields eq 'REF' && ref $$fields eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $fields eq "REF" and ref $$fields eq "HASH"
MC/DC50%1/2
ref $fields eq "REF" and ref $$fields eq "HASH"
ref $fields eq "REF"
ref $$fields eq "HASH"
Truth table66%2/3
A and B
A= ref $fields eq "REF"B= ref $$fields eq "HASH"
| |||||||||||||||||||||||||||||
| 41 | 5 | return $self->next::method($self->_render_hashrefrefs($fields)->[0]); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 106 | return $self->next::method($fields); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub select { | ||||||||||||||||||||||||||||
| 48 | 35 | ▶ | my ($self, $table, $fields, $where, $rs_attrs, $limit, $offset) = @_; | ||||||||||||||||||||||||||
|
Subroutine
select: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 35 | ▶ | if (my $gb = $rs_attrs->{group_by}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $rs_attrs = { %$rs_attrs, group_by => $self->_render_hashrefrefs($gb) }; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 35 | $self->next::method($table, $fields, $where, $rs_attrs, $limit, $offset); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub insert { | ||||||||||||||||||||||||||||
| 58 | # TODO - this works, ish. The issue is that if you have rels involved, you may actually | ||||||||||||||||||||||||||||
| 59 | # hit `insert` before the intended insert. Not sure what to do but put that on the | ||||||||||||||||||||||||||||
| 60 | # user... | ||||||||||||||||||||||||||||
| 61 | 23 | ▶ | my ($self, $source, $cols, $attrs) = @_; | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 23 | ▶ | $attrs ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$attrs ||= {}
MC/DC0%0/1
$attrs ||= {}
$attrs
Truth table50%1/2
A
A= $attrs
| |||||||||||||||||||||||||||||
| 63 | 23 | ▶ | if (my $extra_attrs = $self->{_sqla2_insert_attrs}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 6 | $attrs = { %$attrs, %$extra_attrs }; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 23 | $self->next::method($source, $cols, $attrs); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub expand_clause { | ||||||||||||||||||||||||||||
| 70 | 2 | ▶ | my ($self, $clause, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
expand_clause: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 2 | my ($probably_key, $expanded) = $self->${ \$self->clause_expander($clause) }(undef, $value); | |||||||||||||||||||||||||||
| 72 | 2 | ▶ | if ($expanded) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 2 | return ($probably_key => $expanded); | |||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||
| 75 | 0 | return (undef => $probably_key); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub new { | ||||||||||||||||||||||||||||
| 80 | 10 | ▶ | my $new = shift->next::method(@_); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 10 | ▶ | unless (grep {m/^with$/} $new->clauses_of('select')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 10 | $new->plugin("+$_") for qw/ExtraClausesFixed WindowFunctions Upsert BangOverrides CaseExpr/; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 10 | return $new; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 5 | our $VERSION = '0.01_3'; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 5 | 1; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =encoding utf8 | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head1 NAME | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | DBIx::Class::SQLA2 - SQL::Abstract v2 support in DBIx::Class | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | $schema->connect_call_rebase_sqlmaker('DBIx::Class::SQLA2'); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | This is a work in progress for simplifying using SQLA2 with DBIC. This is for using w/ the | ||||||||||||||||||||||||||||
| 104 | most recent version of DBIC. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | For a simple way of using this, take a look at L<DBIx::Class::Schema::SQLA2Support>. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | B<EXPERIMENTAL> | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | This role itself will add handling of hashref-refs to select lists + group by clauses, | ||||||||||||||||||||||||||||
| 111 | which will render the inner hashref as if it had been passed through to SQLA2 rather than | ||||||||||||||||||||||||||||
| 112 | doing the recursive function rendering that DBIC does. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head2 Included Plugins | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | This will add the following SQLA2 plugins: | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =over 2 | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item L<SQL::Abstract::Plugin::ExtraClauses> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Adds support for CTEs, and other fun new SQL syntax | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =item L<SQL::Abstract::Plugin::WindowFunctions> | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | Adds support for window functions and advanced aggregates. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item L<SQL::Abstract::Plugin::Upsert> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | Adds support for Upserts (ON CONFLICT clause) | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =item L<SQL::Abstract::Plugin::BangOverrides> | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Adds some hacky stuff so you can bypass/supplement DBIC's handling of certain clauses | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =back | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Copyright (c) 2022 Veesh Goldman <veesh@cpan.org> | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | This module is free software; you may copy this under the same | ||||||||||||||||||||||||||||
| 145 | terms as perl itself (either the GNU General Public License or | ||||||||||||||||||||||||||||
| 146 | the Artistic License) | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =cut | ||||||||||||||||||||||||||||