use strictures 1;
use SQL::ReservedWords;
use Data::Query::Constants qw(
- DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE DQ_JOIN DQ_ALIAS
+ DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE DQ_JOIN DQ_ALIAS DQ_ORDER
);
sub new {
my @select = map [
($_->{type} eq DQ_ALIAS
- ? $self->_render_alias($_, 'AS')
+ ? $self->_render_alias($_, $self->_format_keyword('AS'))
: $self->_render($_)
),
','
die "Can't render non-SQL literal";
}
return [
- $dq->{literal},
+ $dq->{literal}, @{$dq->{values}||[]}
];
}
[ $self->_render($left), ',', $self->_render($right) ];
}
+sub _render_where {
+ my ($self, $dq) = @_;
+ my ($from, $where) = @{$dq}{qw(from where)};
+ [
+ ($from ? $self->_render($from) : ()),
+ $self->_format_keyword('WHERE'),
+ $self->_render($where)
+ ]
+}
+
+sub _render_order {
+ my ($self, $dq) = @_;
+ my @ret = (
+ $self->_format_keyword('ORDER BY'),
+ $self->_render($dq->{by}),
+ ($dq->{direction} ? $self->_format_keyword($dq->{direction}) : ())
+ );
+ my $from;
+ while ($from = $dq->{from}) {
+ last unless $from->{type} eq DQ_ORDER;
+ $dq = $from;
+ push @ret, (
+ ',',
+ $self->_render($dq->{by}),
+ ($dq->{direction} ? $self->_format_keyword($dq->{direction}) : ())
+ );
+ }
+ unshift @ret, $self->_render($from) if $from;
+ \@ret;
+}
+
1;