From: Matt S Trout Date: Sat, 6 Apr 2019 03:28:33 +0000 (+0000) Subject: switch insert to clauses system X-Git-Tag: v2.000000~3^2~267 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ed4a77e50e39cd8bfe60e9c8626adbbfb5f1aec;p=dbsrgits%2FSQL-Abstract.git switch insert to clauses system --- diff --git a/lib/SQL/Abstract/Clauses.pm b/lib/SQL/Abstract/Clauses.pm index 70d856c..9f92b00 100644 --- a/lib/SQL/Abstract/Clauses.pm +++ b/lib/SQL/Abstract/Clauses.pm @@ -45,6 +45,15 @@ sub register_defaults { $self->{expand_clause}{'delete.returning'} = sub { shift->_expand_maybe_list_expr(@_, -ident); }; + $self->{clauses_of}{insert} = [ 'insert_into', '', 'values', 'returning' ]; + $self->{expand}{insert} = sub { shift->_expand_statement(@_) }; + $self->{render}{insert} = sub { shift->_render_statement(insert => @_) }; + $self->{expand_clause}{'insert.insert_into'} = sub { + shift->expand_expr(@_, -ident); + }; + $self->{expand_clause}{'insert.returning'} = sub { + shift->_expand_maybe_list_expr(@_, -ident); + }; return $self; } @@ -112,4 +121,14 @@ sub delete { return wantarray ? ($sql, @bind) : $sql; } +sub insert { + my ($self, $table, $data, $options) = @_; + my %clauses = (insert_into => $table, %{$options||{}}); + my ($f_aqt, $v_aqt) = $self->_expand_insert_values($data); + $clauses{''} = $f_aqt if $f_aqt; + $clauses{values} = $v_aqt; + my ($sql, @bind) = $self->render_expr({ -insert => \%clauses }); + return wantarray ? ($sql, @bind) : $sql; +} + 1;