line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::WindowFunctions; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Add support for window functions to DBIx::Class |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
455
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use parent 'DBIx::Class::ResultSet'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
76
|
use Ref::Util qw/ is_plain_arrayref is_plain_hashref /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# RECOMMEND PREREQ: Ref::Util::XS |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 'v0.4.0'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _resolved_attrs { |
20
|
4
|
|
|
4
|
|
46
|
my $rs = $_[0]; |
21
|
4
|
|
|
|
|
9
|
my $attrs = $rs->{attrs}; |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
|
|
|
19
|
my $sqla = $rs->result_source->storage->sql_maker; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
290
|
foreach my $attr (qw/ select +select /) { |
26
|
|
|
|
|
|
|
|
27
|
8
|
100
|
|
|
|
30
|
my $sel = $attrs->{$attr} or next; |
28
|
4
|
|
|
|
|
8
|
my @sel; |
29
|
|
|
|
|
|
|
|
30
|
4
|
50
|
|
|
|
8
|
foreach my $col ( @{ is_plain_arrayref($sel) ? $sel : [$sel] } ) { |
|
4
|
|
|
|
|
21
|
|
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
10
|
push @sel, $col; |
33
|
|
|
|
|
|
|
|
34
|
4
|
50
|
|
|
|
12
|
next unless is_plain_hashref($col); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
my $as = delete $col->{'-as'}; |
37
|
0
|
0
|
|
|
|
0
|
my $over = delete $col->{'-over'} or next; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
0
|
$rs->throw_exception('-over must be a hashref') |
40
|
|
|
|
|
|
|
unless is_plain_hashref($over); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my ( $sql, @bind ) = $sqla->_recurse_fields($col); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my ( $part_sql, @part_bind ) = |
45
|
0
|
|
|
|
|
0
|
$sqla->_recurse_fields( $over->{partition_by} ); |
46
|
0
|
0
|
|
|
|
0
|
if ($part_sql) { |
47
|
0
|
|
|
|
|
0
|
$part_sql = $sqla->_sqlcase('partition by ') . $part_sql; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my ( $order_sql, @order_bind ) = |
51
|
0
|
|
|
|
|
0
|
$sqla->_order_by( $over->{order_by} ); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
$sql .= $sqla->_sqlcase(' over (') . $part_sql . $order_sql . ')'; |
54
|
0
|
0
|
|
|
|
0
|
if ($as) { |
55
|
0
|
|
|
|
|
0
|
$sql .= $sqla->_sqlcase(' as ') . $sqla->_quote($as); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
push @bind, @part_bind, @order_bind; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
$sel[-1] = \[ $sql, @bind ]; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
13
|
$attrs->{$attr} = \@sel; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
|
|
13
|
return $rs->next::method; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |