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
|
|
114468
|
use v5.8; |
|
1
|
|
|
|
|
3
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
378
|
use parent 'DBIx::Class::ResultSet'; |
|
1
|
|
|
|
|
242
|
|
|
1
|
|
|
|
|
3
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 'v0.1.2'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _resolved_attrs { |
16
|
4
|
|
|
4
|
|
483302
|
my $rs = $_[0]; |
17
|
4
|
|
|
|
|
17
|
my $attrs = $rs->{attrs}; |
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
|
|
37
|
my $sqla = $rs->result_source->storage->sql_maker; |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
384
|
foreach my $attr (qw/ select +select /) { |
22
|
|
|
|
|
|
|
|
23
|
8
|
100
|
|
|
|
45
|
my $sel = $attrs->{$attr} or next; |
24
|
4
|
|
|
|
|
14
|
my @sel; |
25
|
|
|
|
|
|
|
|
26
|
4
|
50
|
|
|
|
9
|
foreach my $col ( @{ ref $sel eq 'ARRAY' ? $sel : [$sel] } ) { |
|
4
|
|
|
|
|
29
|
|
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
16
|
push @sel, $col; |
29
|
|
|
|
|
|
|
|
30
|
4
|
50
|
|
|
|
20
|
next unless ref $col eq 'HASH'; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
17
|
my $as = delete $col->{'-as'}; |
33
|
4
|
50
|
|
|
|
17
|
my $over = delete $col->{'-over'} or next; |
34
|
|
|
|
|
|
|
|
35
|
4
|
50
|
|
|
|
19
|
$rs->throw_exception('-over must be a hashref') |
36
|
|
|
|
|
|
|
unless ref $over eq 'HASH'; |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
44
|
my ( $sql, @bind ) = $sqla->_recurse_fields($col); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my ( $part_sql, @part_bind ) = |
41
|
4
|
|
|
|
|
348
|
$sqla->_recurse_fields( $over->{partition_by} ); |
42
|
4
|
100
|
|
|
|
531
|
if ($part_sql) { |
43
|
3
|
|
|
|
|
11
|
$part_sql = $sqla->_sqlcase('partition by ') . $part_sql; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my ( $order_sql, @order_bind ) = |
47
|
4
|
|
|
|
|
34
|
$sqla->_order_by( $over->{order_by} ); |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
745
|
$sql .= $sqla->_sqlcase(' over (') . $part_sql . $order_sql . ')'; |
50
|
4
|
100
|
|
|
|
37
|
if ($as) { |
51
|
2
|
|
|
|
|
6
|
$sql .= $sqla->_sqlcase(' as ') . $sqla->_quote($as); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
42
|
push @bind, @part_bind, @order_bind; |
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
17
|
$sel[-1] = \[ $sql, @bind ]; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
20
|
$attrs->{$attr} = \@sel; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
13
|
return $rs->next::method; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |