use base qw(Exporter);
-our @EXPORT = qw(expr SELECT AS FROM BY JOIN ON LEFT WHERE ORDER GROUP);
+our @EXPORT = qw(
+ expr SELECT AS FROM BY JOIN ON LEFT WHERE ORDER GROUP DESC
+);
sub expr (&) {
_run_expr($_[0])->{expr};
$from_dq = { %{+shift}, left => $from_dq };
}
if (is_Where($_[0])) {
- $from_dq = Where(shift->{where}, $from_dq);
+ my $where = shift->{where};
+ if (is_Select($from_dq)) {
+ $from_dq = Select($from_dq->{select}, Where($where, $from_dq->{from}));
+ } else {
+ $from_dq = Where($where, $from_dq);
+ }
+ }
+ while (is_Order($_[0])) {
+ my $order = shift;
+ $from_dq = Order($order->{by}, $order->{reverse}, $from_dq);
}
return $from_dq;
}
return Where(_value(_run_expr($w))), @_;
}
+sub DESC { bless({}, 'LIES::DESC'), @_ }
+
+sub ORDER {
+ my @order = map _value($_), _run_expr(shift);
+ my $reverse = do {
+ if ($_[0]->$_isa('LIES::DESC')) {
+ shift; 1;
+ } else {
+ 0;
+ }
+ };
+ return compose { Order($b, $reverse, $a) } @order, undef;
+}
+
1;
ON { $_->cd->artistid eq $_->artist->id }
WHERE { $_->artist->age > 25 }
);
+DwarnL render_expr(ORDER BY { $_->foo, $_->bar, $_->baz } DESC);
+
+my $basic = SELECT { $_->cd->name } FROM { $_->cds, AS 'cd' };
+
+DwarnL render_expr(
+ FROM { $basic } WHERE { $_->year > 2000 }
+);
+
+DwarnL render_expr(
+ FROM { $basic } ORDER BY { $_->year }
+);
+
+DwarnL render_expr(
+ SELECT { $_->cd->name } FROM { $_->cds, AS 'cd' } ORDER BY { $_->year }
+);