use base qw(Exporter);
our @EXPORT = qw(
- expr SELECT AS FROM BY JOIN ON LEFT WHERE ORDER GROUP DESC
+ expr SELECT AS FROM BY JOIN ON LEFT WHERE ORDER GROUP DESC LIMIT OFFSET
);
sub expr (&) {
);
}
- return Select(\@final, $_[0]);
+ my $final = Select(\@final, shift);
+
+ if (is_Slice($_[0])) {
+ my ($limit, $offset) = @{+shift}{qw(limit offset)};
+ $final = Slice($offset, $limit, $final);
+ }
+
+ return $final;
}
sub BY (&;@) { @_ }
my $order = shift;
$from_dq = Order($order->{by}, $order->{reverse}, $from_dq);
}
- return $from_dq;
+ return ($from_dq, @_);
}
sub LEFT {
}
sub JOIN (&;@) {
- my $join = FROM(\&{+shift});
+ my ($join) = FROM(\&{+shift});
my $on = do {
if ($_[0]->$_isa('LIES::ON')) {
${+shift}
0;
}
};
- return compose { Order($b, $reverse, $a) } @order, undef;
+ return ((compose { Order($b, $reverse, $a) } @order, undef), @_);
+}
+
+sub LIMIT (&;@) {
+ my ($limit) = map _value($_), _run_expr(shift);
+ if (is_Slice($_[0])) {
+ my $slice = shift;
+ return +{ %{$slice}, limit => $limit }, @_;
+ }
+ return Slice(undef, $limit), @_;
+}
+
+sub OFFSET (&;@) {
+ my ($offset) = map _value($_), _run_expr(shift);
+ return Slice($offset, undef), @_;
}
1;
use strictures;
use Data::Query::ExprDeclare;
use Data::Query::Renderer::SQL::Naive;
+use Moo::Role ();
use Devel::Dwarn;
my $renderer = Data::Query::Renderer::SQL::Naive->new;
DwarnL render_expr(
SELECT { $_->cd->name } FROM { $_->cds, AS 'cd' } ORDER BY { $_->year }
);
+
+$renderer = Moo::Role->create_class_with_roles(
+ 'Data::Query::Renderer::SQL::Naive',
+ 'Data::Query::Renderer::SQL::Slice::LimitOffset'
+)->new;
+
+DwarnL render_expr(
+ SELECT { $_->cd->name }
+ FROM { $_->cds, AS 'cd' }
+ ORDER BY { $_->year }
+ LIMIT { 10 } OFFSET { 10 }
+);