From: Matt S Trout Date: Sun, 17 Mar 2013 22:31:06 +0000 (+0000) Subject: RETURNING ... INTO support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bb5b7a0d0c0850786c5c882694520314b3d2abd6;p=dbsrgits%2FData-Query.git RETURNING ... INTO support --- diff --git a/lib/Data/Query/ExprHelpers.pm b/lib/Data/Query/ExprHelpers.pm index be56f2f..674bacc 100644 --- a/lib/Data/Query/ExprHelpers.pm +++ b/lib/Data/Query/ExprHelpers.pm @@ -5,7 +5,11 @@ use Data::Query::Constants; use base qw(Exporter); -our @EXPORT = qw(perl_scalar_value perl_operator Literal Identifier compose); +our @EXPORT = qw( + perl_scalar_value perl_operator Literal Identifier compose intersperse +); + +sub intersperse { my $i = shift; my @i = map +($_, $i), @_; pop @i; @i } sub perl_scalar_value { +{ diff --git a/lib/Data/Query/Renderer/SQL/Dialect/ReturnInto.pm b/lib/Data/Query/Renderer/SQL/Dialect/ReturnInto.pm new file mode 100644 index 0000000..2d3b621 --- /dev/null +++ b/lib/Data/Query/Renderer/SQL/Dialect/ReturnInto.pm @@ -0,0 +1,20 @@ +package Data::Query::Renderer::SQL::Dialect::ReturnInto; + +use Data::Query::ExprHelpers; +use Moo::Role; + +around _render_insert => sub { + my ($orig, $self) = (shift, shift); + my ($dq) = @_; + if (my $into = $dq->{__PACKAGE__.'.into'}) { + my @ret = @{$self->$orig(@_)}; + return [ + @ret, $self->_format_keyword('INTO'), + intersperse(',', map $self->_render($_), @$into) + ]; + } else { + return $self->$orig(@_); + } +}; + +1; diff --git a/lib/Data/Query/Renderer/SQL/Naive.pm b/lib/Data/Query/Renderer/SQL/Naive.pm index aac3c73..fb18512 100644 --- a/lib/Data/Query/Renderer/SQL/Naive.pm +++ b/lib/Data/Query/Renderer/SQL/Naive.pm @@ -2,8 +2,6 @@ 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::ExprHelpers;