line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::SQLA2; |
2
|
5
|
|
|
5
|
|
117604
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
178
|
|
3
|
5
|
|
|
5
|
|
38
|
use warnings; |
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
154
|
|
4
|
5
|
|
|
5
|
|
37
|
use feature 'postderef'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
541
|
|
5
|
5
|
|
|
5
|
|
32
|
no warnings 'experimental::postderef'; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
185
|
|
6
|
5
|
|
|
5
|
|
29
|
use mro 'c3'; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
32
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
|
|
4553
|
use base qw( |
9
|
|
|
|
|
|
|
DBIx::Class::SQLMaker::ClassicExtensions |
10
|
|
|
|
|
|
|
SQL::Abstract |
11
|
|
|
|
|
|
|
SQL::Abstract::Classic |
12
|
5
|
|
|
5
|
|
173
|
); |
|
5
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
107119
|
use Role::Tiny; |
|
5
|
|
|
|
|
18017
|
|
|
5
|
|
|
|
|
39
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_group_accessors(simple => '_connection_info'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _render_hashrefrefs { |
19
|
5
|
|
|
5
|
|
15
|
my ($self, $list) = @_; |
20
|
5
|
50
|
|
|
|
71
|
my @fields = ref $list eq 'ARRAY' ? @$list : $list; |
21
|
|
|
|
|
|
|
return [ |
22
|
|
|
|
|
|
|
map { |
23
|
5
|
|
|
|
|
16
|
ref $_ eq 'REF' && ref $$_ eq 'HASH' |
24
|
5
|
50
|
33
|
|
|
37
|
? do { |
25
|
5
|
|
|
|
|
26
|
my %f = $$_->%*; |
26
|
5
|
|
|
|
|
44
|
my $as = delete $f{-as}; |
27
|
|
|
|
|
|
|
\[ |
28
|
5
|
50
|
|
|
|
67
|
$as |
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
|
114
|
|
|
114
|
|
46056
|
my ($self, $fields) = @_; |
40
|
114
|
100
|
66
|
|
|
330
|
if (ref $fields eq 'REF' && ref $$fields eq 'HASH') { |
41
|
5
|
|
|
|
|
75
|
return $self->next::method($self->_render_hashrefrefs($fields)->[0]); |
42
|
|
|
|
|
|
|
} |
43
|
109
|
|
|
|
|
251
|
return $self->next::method($fields); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub select { |
48
|
36
|
|
|
36
|
1
|
285535
|
my ($self, $table, $fields, $where, $rs_attrs, $limit, $offset) = @_; |
49
|
|
|
|
|
|
|
|
50
|
36
|
50
|
|
|
|
202
|
if (my $gb = $rs_attrs->{group_by}) { |
51
|
0
|
|
|
|
|
0
|
$rs_attrs = { %$rs_attrs, group_by => $self->_render_hashrefrefs($gb) }; |
52
|
|
|
|
|
|
|
} |
53
|
36
|
|
|
|
|
208
|
$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
|
|
|
23
|
1
|
40621
|
my ($self, $source, $cols, $attrs) = @_; |
62
|
23
|
|
50
|
|
|
261
|
$attrs ||= {}; |
63
|
23
|
100
|
|
|
|
130
|
if (my $extra_attrs = $self->{_sqla2_insert_attrs}) { |
64
|
6
|
|
|
|
|
30
|
$attrs = { %$attrs, %$extra_attrs }; |
65
|
|
|
|
|
|
|
} |
66
|
23
|
|
|
|
|
150
|
$self->next::method($source, $cols, $attrs); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub expand_clause { |
70
|
2
|
|
|
2
|
0
|
10
|
my ($self, $clause, $value) = @_; |
71
|
2
|
|
|
|
|
4
|
my ($probably_key, $expanded) = $self->${ \$self->clause_expander($clause) }(undef, $value); |
|
2
|
|
|
|
|
53
|
|
72
|
2
|
50
|
|
|
|
934
|
if ($expanded) { |
73
|
2
|
|
|
|
|
12
|
return ($probably_key => $expanded); |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
0
|
return (undef => $probably_key); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new { |
80
|
10
|
|
|
10
|
1
|
3741
|
my $new = shift->next::method(@_); |
81
|
10
|
50
|
|
|
|
3061
|
unless (grep {m/^with$/} $new->clauses_of('select')) { |
|
40
|
|
|
|
|
295
|
|
82
|
10
|
|
|
|
|
93
|
$new->plugin("+$_") for qw/ExtraClausesFixed WindowFunctions Upsert BangOverrides CaseExpr/; |
83
|
|
|
|
|
|
|
} |
84
|
10
|
|
|
|
|
639
|
return $new; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
our $VERSION = '0.01_4'; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
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. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
B |
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 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Adds support for CTEs, and other fun new SQL syntax |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Adds support for window functions and advanced aggregates. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item L |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Adds support for Upserts (ON CONFLICT clause) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item L |
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 |
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 |