| 1 | package SQL::Wizard::Expr::Select; | ||||||||||
| 2 | |||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 14 | ▶ | use Storable qw(dclone); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 14 | ▶ | use parent 'SQL::Wizard::Expr'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 14 | ▶ | use SQL::Wizard::Expr::Compound; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 131 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 10 | 131 | my ($class, %args) = @_; | |||||||||
| 11 | 131 | $class->SUPER::new(%args); | |||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | # Build a Select node from the standard -key => value API args. | ||||||||||
| 15 | # Accepts extra key/value pairs (e.g. _cte, _renderer) merged in. | ||||||||||
| 16 | 131 | ▶ | sub from_args { | ||||||||
|
Subroutine
from_args: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||
| 17 | 131 | my ($class, %args) = @_; | |||||||||
| 18 | 131 | ▶ | Carp::confess("select requires -from") unless $args{'-from'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 131 | my %node; | |||||||||
| 20 | 131 | ▶ | $node{distinct} = $args{'-distinct'} if $args{'-distinct'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 131 | ▶ | $node{columns} = $args{'-columns'} if $args{'-columns'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 131 | ▶ | $node{from} = $args{'-from'} if $args{'-from'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 131 | ▶ | $node{where} = $args{'-where'} if $args{'-where'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 131 | ▶ | $node{group_by} = $args{'-group_by'} if $args{'-group_by'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 131 | ▶ | $node{having} = $args{'-having'} if $args{'-having'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 131 | ▶ | $node{order_by} = $args{'-order_by'} if $args{'-order_by'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 131 | ▶ | $node{limit} = $args{'-limit'} if defined $args{'-limit'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 131 | ▶ | $node{offset} = $args{'-offset'} if defined $args{'-offset'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 131 | ▶ | $node{window} = $args{'-window'} if $args{'-window'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 131 | ▶ | $node{_cte} = $args{_cte} if $args{_cte}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 131 | ▶ | $node{_renderer} = $args{_renderer} if $args{_renderer}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 131 | $class->new(%node); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | # Immutable modifiers — return cloned objects | ||||||||||
| 36 | |||||||||||
| 37 | 1 | ▶ | sub distinct { | ||||||||
|
Subroutine
distinct: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 38 | 1 | my ($self) = @_; | |||||||||
| 39 | 1 | my $clone = dclone($self); | |||||||||
| 40 | 1 | $clone->{distinct} = 1; | |||||||||
| 41 | 1 | return $clone; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | ▶ | sub where { | ||||||||
|
Subroutine
where: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 45 | 2 | my ($self, $where) = @_; | |||||||||
| 46 | 2 | my $clone = dclone($self); | |||||||||
| 47 | 2 | $clone->{where} = $where; | |||||||||
| 48 | 2 | return $clone; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 2 | ▶ | sub add_where { | ||||||||
|
Subroutine
add_where: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 52 | 2 | my ($self, $extra) = @_; | |||||||||
| 53 | 2 | my $clone = dclone($self); | |||||||||
| 54 | 2 | ▶ | if ($clone->{where}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 2 | $clone->{where} = [-and => $clone->{where}, $extra]; | |||||||||
| 56 | } else { | ||||||||||
| 57 | 0 | $clone->{where} = $extra; | |||||||||
| 58 | } | ||||||||||
| 59 | 2 | return $clone; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | ▶ | sub columns { | ||||||||
|
Subroutine
columns: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 63 | 1 | my ($self, $cols) = @_; | |||||||||
| 64 | 1 | my $clone = dclone($self); | |||||||||
| 65 | 1 | $clone->{columns} = $cols; | |||||||||
| 66 | 1 | return $clone; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | sub order_by { | ||||||||
|
Subroutine
order_by: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 70 | 2 | my ($self, @order) = @_; | |||||||||
| 71 | 2 | my $clone = dclone($self); | |||||||||
| 72 | 2 | ▶ | $clone->{order_by} = @order == 1 ? $order[0] : \@order; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 2 | return $clone; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 3 | ▶ | sub limit { | ||||||||
|
Subroutine
limit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 77 | 3 | my ($self, $limit) = @_; | |||||||||
| 78 | 3 | my $clone = dclone($self); | |||||||||
| 79 | 3 | $clone->{limit} = $limit; | |||||||||
| 80 | 3 | return $clone; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 2 | ▶ | sub offset { | ||||||||
|
Subroutine
offset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 2 | my ($self, $offset) = @_; | |||||||||
| 85 | 2 | my $clone = dclone($self); | |||||||||
| 86 | 2 | $clone->{offset} = $offset; | |||||||||
| 87 | 2 | return $clone; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | # Compound query methods | ||||||||||
| 91 | |||||||||||
| 92 | 5 | ▶ | sub union { | ||||||||
|
Subroutine
union: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 93 | 5 | my ($self, $other) = @_; | |||||||||
| 94 | SQL::Wizard::Expr::Compound->new( | ||||||||||
| 95 | queries => [{ type => undef, query => $self }, { type => 'UNION', query => $other }], | ||||||||||
| 96 | _renderer => $self->{_renderer}, | ||||||||||
| 97 | 5 | ); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 1 | ▶ | sub union_all { | ||||||||
|
Subroutine
union_all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 101 | 1 | my ($self, $other) = @_; | |||||||||
| 102 | SQL::Wizard::Expr::Compound->new( | ||||||||||
| 103 | queries => [{ type => undef, query => $self }, { type => 'UNION ALL', query => $other }], | ||||||||||
| 104 | _renderer => $self->{_renderer}, | ||||||||||
| 105 | 1 | ); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 1 | ▶ | sub intersect { | ||||||||
|
Subroutine
intersect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 109 | 1 | my ($self, $other) = @_; | |||||||||
| 110 | SQL::Wizard::Expr::Compound->new( | ||||||||||
| 111 | queries => [{ type => undef, query => $self }, { type => 'INTERSECT', query => $other }], | ||||||||||
| 112 | _renderer => $self->{_renderer}, | ||||||||||
| 113 | 1 | ); | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 1 | ▶ | sub except { | ||||||||
|
Subroutine
except: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 117 | 1 | my ($self, $other) = @_; | |||||||||
| 118 | SQL::Wizard::Expr::Compound->new( | ||||||||||
| 119 | queries => [{ type => undef, query => $self }, { type => 'EXCEPT', query => $other }], | ||||||||||
| 120 | _renderer => $self->{_renderer}, | ||||||||||
| 121 | 1 | ); | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 14 | 1; | |||||||||