package Data::Query::Renderer::SQL::Naive;
use strictures 1;
+
+sub intersperse { my $i = shift; my @i = map +($_, $i), @_; pop @i; @i }
+
use SQL::ReservedWords;
use Data::Query::Constants qw(
DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE DQ_JOIN DQ_ALIAS DQ_ORDER DQ_LITERAL
sub _render_delete {
my ($self, $dq) = @_;
- [ $self->_format_keyword('DELETE FROM'), @{$self->_render($dq->{from})} ];
+ my ($target, $where) = @{$dq}{qw(target where)};
+ [ $self->_format_keyword('DELETE FROM'),
+ $self->_render($target),
+ ($where
+ ? ($self->_format_keyword('WHERE'), $self->_render($where))
+ : ())
+ ];
+}
+
+sub _render_update {
+ my ($self, $dq) = @_;
+ my ($target, $set, $where) = @{$dq}{qw(target set where)};
+ my @rendered_set = intersperse(
+ ',', map [ intersperse('=', map $self->_render($_), @$_) ], @{$set}
+ );
+ [ $self->_format_keyword('UPDATE'),
+ $self->_render($target),
+ $self->_format_keyword('SET'),
+ @rendered_set,
+ ($where
+ ? ($self->_format_keyword('WHERE'), $self->_render($where))
+ : ())
+ ];
}
1;