From: Matt S Trout Date: Sat, 6 Apr 2019 03:28:33 +0000 (+0000) Subject: switch insert to clauses system X-Git-Tag: v1.90_01~246 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39544e0ebbfa3015024e1a46409c86e4c96d5d7f;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;