push @parts, [ $self->_insert_returning($options) ];
}
- my ($sql, @bind) = $self->_join_parts(' ', @parts);
-
- return wantarray ? ($sql, @bind) : $sql;
+ return $self->_join_parts(' ', @parts);
}
sub _expand_insert_values {
sub render_expr {
my ($self, $expr, $default_scalar_to) = @_;
- $self->render_aqt($self->expand_expr($expr, $default_scalar_to));
+ my ($sql, @bind) = $self->render_aqt(
+ $self->expand_expr($expr, $default_scalar_to)
+ );
+ return (wantarray ? ($sql, @bind) : $sql);
}
sub _normalize_op {
my ($self, $join, @parts) = @_;
return (
join($join, map $_->[0], @parts),
- map @{$_}[1..$#$_], @parts
+ (wantarray ? (map @{$_}[1..$#$_], @parts) : ()),
);
}
$self->{render}{insert} = sub { shift->_render_statement(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 => [
+ shift->_expand_maybe_list_expr(@_, -ident)
+ ] } if ref($_[1]) eq 'ARRAY';
+ return $_[1]; # should maybe still expand somewhat?
+ };
$self->{expand_clause}{'insert.values'} = '_expand_insert_clause_values';
$self->{expand_clause}{'insert.returning'} = sub {
shift->_expand_maybe_list_expr(@_, -ident);
sub select {
my ($self, @args) = @_;
+
+ return $self->render_expr({ -select => $_[1] }) if ref($_[1]) eq 'HASH';
+
my %clauses;
@clauses{qw(from select where order_by)} = @args;
$clauses{select} = { -literal => [ $clauses{select}||'*' ] }
unless ref($clauses{select});
- my ($sql, @bind) = $self->render_expr({ -select => \%clauses });
- return wantarray ? ($sql, @bind) : $sql;
+ return $self->render_expr({ -select => \%clauses });
}
sub update {
my ($self, $table, $set, $where, $options) = @_;
+
+ return $self->render_expr({ -update => $_[1] }) if ref($_[1]) eq 'HASH';
+
my %clauses;
@clauses{qw(target set where)} = ($table, $set, $where);
puke "Unsupported data type specified to \$sql->update"
unless ref($clauses{set}) eq 'HASH';
@clauses{keys %$options} = values %$options;
- my ($sql, @bind) = $self->render_expr({ -update => \%clauses });
- return wantarray ? ($sql, @bind) : $sql;
+ return $self->render_expr({ -update => \%clauses });
}
sub delete {
my ($self, $table, $where, $options) = @_;
+
+ return $self->render_expr({ -delete => $_[1] }) if ref($_[1]) eq 'HASH';
+
my %clauses = (target => $table, where => $where, %{$options||{}});
- my ($sql, @bind) = $self->render_expr({ -delete => \%clauses });
- return wantarray ? ($sql, @bind) : $sql;
+ return $self->render_expr({ -delete => \%clauses });
}
sub insert {
my ($self, $table, $data, $options) = @_;
+
+ return $self->render_expr({ -insert => $_[1] }) if ref($_[1]) eq 'HASH';
+
my %clauses = (target => $table, values => $data, %{$options||{}});
- my ($sql, @bind) = $self->render_expr({ -insert => \%clauses });
- return wantarray ? ($sql, @bind) : $sql;
+ return $self->render_expr({ -insert => \%clauses });
}
sub _expand_insert_clause_target {