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