package Data::Query::Renderer::SQL::Slice::FetchFirst;
+use List::Util qw(reduce);
use Data::Query::ExprHelpers;
use Moo::Role;
push @order_nodes, $order;
$order = $order->{from};
}
- my $inside_order = $order;
- $inside_order = Order($_->{by}, $_->{reverse}, $inside_order)
- for reverse @order_nodes;
+ my $inside_order = reduce {
+ Order($b->{by}, $b->{reverse}, $a)
+ } $order, reverse @order_nodes;
my $inside_select = Select(\@inside_select_list, $inside_order);
my $limit_plus_offset = +{
%{$dq->{limit}}, value => $dq->{limit}{value} + $dq->{offset}{value}
$default_inside_alias,
Slice(undef, $limit_plus_offset, $inside_select)
);
- my $outside_order = $bridge_from;
- $outside_order = Order($order_map{$_->{by}}, !$_->{reverse}, $outside_order)
- for reverse @order_nodes;
+ my $outside_order = reduce {
+ Order($order_map{$b->{by}}, !$b->{reverse}, $a)
+ } $bridge_from, reverse @order_nodes;
my $outside_select = Select(
(
$dq->{preserve_order}
);
my $final = Slice(undef, $dq->{limit}, $outside_select);
if ($dq->{preserve_order}) {
- $final = Alias($default_inside_alias, $final);
- $final = Order($order_map{$_->{by}}, $_->{reverse}, $final)
- for reverse @order_nodes;
- $final = Select(\@outside_select_list, $final);
+ $final = Select(
+ \@outside_select_list,
+ reduce {
+ Order($order_map{$b->{by}}, $b->{reverse}, $a)
+ } Alias($default_inside_alias, $final), reverse @order_nodes
+ );
}
return $self->_render($final);
}