From: Matt S Trout Date: Sat, 6 Apr 2019 02:25:09 +0000 (+0000) Subject: delete as clauses X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=77e8c03db002e7c6a8dc45a2ba621d00bd31d5d2;p=scpubgit%2FQ-Branch.git delete as clauses --- diff --git a/lib/SQL/Abstract/Clauses.pm b/lib/SQL/Abstract/Clauses.pm index c640109..70d856c 100644 --- a/lib/SQL/Abstract/Clauses.pm +++ b/lib/SQL/Abstract/Clauses.pm @@ -35,6 +35,16 @@ sub register_defaults { $self->{expand_clause}{'update.returning'} = sub { shift->_expand_maybe_list_expr(@_, -ident); }; + $self->{clauses_of}{delete} = [ qw(delete_from where returning) ]; + $self->{expand}{delete} = sub { shift->_expand_statement(@_) }; + $self->{render}{delete} = sub { shift->_render_statement(delete => @_) }; + $self->{expand_clause}{'delete.delete_from'} = sub { + $_[0]->_expand_maybe_list_expr($_[1], -ident) + }; + $self->{expand_clause}{'delete.where'} = 'expand_expr'; + $self->{expand_clause}{'delete.returning'} = sub { + shift->_expand_maybe_list_expr(@_, -ident); + }; return $self; } @@ -95,4 +105,11 @@ sub update { return wantarray ? ($sql, @bind) : $sql; } +sub delete { + my ($self, $table, $where, $options) = @_; + my %clauses = (delete_from => $table, where => $where, %{$options||{}}); + my ($sql, @bind) = $self->render_expr({ -delete => \%clauses }); + return wantarray ? ($sql, @bind) : $sql; +} + 1;