return +(with => { ($type ? (type => $type) : ()), queries => \@exp });
});
$self->clause_expander('select.with_recursive', $with_expander);
- $self->clause_renderer('select.with' => sub {
+ $self->clause_renderer('select.with' => my $with_renderer = sub {
my ($self, undef, $with) = @_;
my $q_part = $self->join_query_parts(', ',
map {
$q_part,
);
});
+ foreach my $stmt (qw(insert update delete)) {
+ $self->clauses_of($stmt => 'with', $self->clauses_of($stmt));
+ $self->clause_expander("${stmt}.$_", $with_expander)
+ for qw(with with_recursive);
+ $self->clause_renderer("${stmt}.with", $with_renderer);
+ }
+ $self->expander(cast => sub {
+ return { -func => [ cast => $_[2] ] } if ref($_[2]) eq 'HASH';
+ my ($cast, $to) = @{$_[2]};
+ +{ -func => [ cast => { -as => [
+ $self->expand_expr($cast),
+ $self->expand_expr($to, -ident),
+ ] } ] };
+ });
return $self;
}
$proto{to} = $self->expand_expr({ -as => [ $proto{to}, $as ] });
}
if (defined($proto{using}) and ref(my $using = $proto{using}) ne 'HASH') {
- $proto{using} = { -row => [
+ $proto{using} = [
map [ $self->expand_expr($_, -ident) ],
ref($using) eq 'ARRAY' ? @$using: $using
- ] };
+ ];
}
my %ret = map +($_ => $self->expand_expr($proto{$_}, -ident)),
sort keys %proto;
my @parts = (
$args->{from},
$self->format_keyword(join '_', ($args->{type}||()), 'join'),
- (map +($_->{-ident} || $_->{-as} ? $_ : { -row => [ $_ ] }), $args->{to}),
+ (map +($_->{-ident} || $_->{-as} ? $_ : ('(', $_, ')')), $args->{to}),
($args->{on} ? (
$self->format_keyword('on') ,
$args->{on},
) : ()),
($args->{using} ? (
$self->format_keyword('using'),
- $args->{using},
+ '(', $args->{using}, ')',
) : ()),
);
return $self->join_query_parts(' ', @parts);
my ($self, undef, $args) = @_;
my ($thing, $alias) = @$args;
return $self->join_query_parts(
- ' ',
+ ' '.$self->format_keyword('as').' ',
$thing,
- $self->format_keyword('as'),
$alias,
);
}