From: Matt S Trout Date: Thu, 18 Apr 2019 18:43:13 +0000 (+0000) Subject: extract remaining insert clause expansion handling to methods X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ddbe2793fdede940f3477dfc349679a4aa89384b;p=scpubgit%2FQ-Branch.git extract remaining insert clause expansion handling to methods --- diff --git a/lib/SQL/Abstract/Clauses.pm b/lib/SQL/Abstract/Clauses.pm index 5fd0fdd..1d1f05e 100644 --- a/lib/SQL/Abstract/Clauses.pm +++ b/lib/SQL/Abstract/Clauses.pm @@ -44,18 +44,10 @@ sub register_defaults { ]; $self->{expand}{insert} = sub { shift->_expand_statement(@_) }; $self->{render}{insert} = sub { shift->_render_statement(@_) }; + $self->{expand_clause}{"insert.$_"} = "_expand_insert_clause_$_" + for @{$self->{clauses_of}{insert}}; $self->{expand_clause}{'insert.into'} = '_expand_insert_clause_target'; - $self->{expand_clause}{'insert.target'} = '_expand_insert_clause_target'; - $self->{expand_clause}{'insert.fields'} = sub { - return +{ -row => [ - $_[0]->_expand_maybe_list_expr($_[2], -ident) - ] } if ref($_[2]) eq 'ARRAY'; - return $_[2]; # should maybe still expand somewhat? - }; - $self->{expand_clause}{'insert.values'} = '_expand_insert_clause_values'; - $self->{expand_clause}{'insert.returning'} = sub { - $_[0]->_expand_maybe_list_expr($_[2], -ident); - }; + $self->{expand_clause}{'insert.values'} = '_expand_insert_clause_from'; $self->{render_clause}{'insert.fields'} = sub { return $_[0]->render_aqt($_[2]); }; @@ -242,7 +234,14 @@ sub _expand_insert_clause_target { +(target => $_[0]->_expand_maybe_list_expr($_[2], -ident)); } -sub _expand_insert_clause_values { +sub _expand_insert_clause_fields { + return +{ -row => [ + $_[0]->_expand_maybe_list_expr($_[2], -ident) + ] } if ref($_[2]) eq 'ARRAY'; + return $_[2]; # should maybe still expand somewhat? +} + +sub _expand_insert_clause_from { my ($self, undef, $data) = @_; if (ref($data) eq 'HASH' and (keys(%$data))[0] =~ /^-/) { return $self->expand_expr($data); @@ -252,6 +251,10 @@ sub _expand_insert_clause_values { return (from => { -values => $v_aqt }, ($f_aqt ? (fields => $f_aqt) : ())); } +sub _expand_insert_clause_returning { + +(returning => $_[0]->_expand_maybe_list_expr($_[2], -ident)); +} + sub _expand_values { my ($self, undef, $values) = @_; return { -values => [