confess "'columns' should be an array ref, not " . dump($ast->{columns})
unless is_ArrayRef($ast->{columns});
- my $cols = join ($self->list_separator, map { $self->dispatch($_) } @{ $ast->{columns}});
+ my $cols = $self->_list({-type => 'list', args => $ast->{columns} });
my @output = (
SELECT => $cols
return join(' ', @output);
}
- method _where(ArrayAST $ast) {
- my (undef, @clauses) = @$ast;
+ method _join(HashRef $ast) {
+ my ($from, $to) = @{ $ast->{args} };
- return 'WHERE ' . $self->_recurse_where(\@clauses);
+ my $output = $self->dispatch($from)
+ . ' JOIN '
+ . $self->dispatch($to);
+
+ $output .= exists $ast->{on}
+ ? ' ON (' . $self->_expr( $ast->{on} )
+ : ' USING (' .$self->dispatch($ast->{using} || croak "No 'on' or 'join' clause passed to -join");
+
+ $output .= ")";
+ return $output;
+
}
method _order_by(AST $ast) {
return $ret;
}
- method _join(HashRef $ast) {
-
- my $output = 'JOIN ' . $self->dispatch($ast->{tablespec});
-
- $output .= exists $ast->{on}
- ? ' ON (' . $self->_expr( $ast->{on} )
- : ' USING (' .$self->dispatch($ast->{using} || croak "No 'on' or 'join' clause passed to -join");
-
- $output .= ")";
- return $output;
-
- }
method _list(AST $ast) {
my @items = @{$ast->{args}};
), "SELECT me.id, me.foo_id AS foo FROM foo AS me",
"simple select clause";
-__END__
is $sqla->dispatch(
{ -type => 'select',
- tablespec => {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
columns => [
{ -type => 'name', args => [qw/me id/] },
{ -type => 'alias', ident => { -type => 'name', args => [qw/me foo_id/] }, as => 'foo' },
{ -type => 'name', args => [qw/bar name/] },
- ]
+ ],
+ tablespec => {
+ -type => 'join',
+ args => [
+ {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
+ {-type => 'name', args => [qw/bar/] },
+ ],
+ on => {
+ -type => 'expr',
+ op => '==',
+ args => [
+ {-type => 'name', args => [qw/bar id/]},
+ {-type => 'name', args => [qw/me bar_id/]}
+ ],
+ }
+ },
}
- { -type => 'select',
- from => [-alias => [-name => 'foo'] => 'me' ],
- columns => [ -list =>
- [ -name => qw/me id/ ],
- [ -alias => [ -name => qw/me foo_id/ ], 'foo' ],
- [ -name => qw/bar name/ ],
- ],
- join => {
- tablespec => [-name => qw/bar/],
- on => [ '==', [-name => qw/bar id/], [ -name => qw/me bar_id/ ] ],
- }
- }
), "SELECT me.id, me.foo_id AS foo, bar.name FROM foo AS me JOIN bar ON (bar.id = me.bar_id)",
"select with join clause";
-
+__END__