}
method _join(HashRef $ast) {
- confess "'args' option to join should be an array ref, not " . dump($ast->{args})
- unless is_ArrayRef($ast->{args});
-
- my ($from, $to) = @{ $ast->{args} };
# TODO: Validate join type
my $type = $ast->{join_type} || "";
- my @output = $self->dispatch($from);
+ my @output = $self->dispatch($ast->{lhs});
push @output, uc $type if $type;
- push @output, "JOIN", $self->dispatch($to);
+ push @output, "JOIN", $self->dispatch($ast->{rhs});
push @output,
exists $ast->{on}
my $sqla = SQL::Abstract->create(1);
+my $foo = {-type => name => args => [qw/foo/]};
+my $bar = {-type => name => args => [qw/bar/]},
+my $fnord = {-type => name => args => [qw/fnord/]};
+
+my $foo_id = { -type => 'name', args => [qw/foo id/] };
+my $me_foo_id = { -type => 'name', args => [qw/me foo_id/] };
+
is $sqla->dispatch(
{ -type => 'join',
- args => [
- {-type => name => args => [qw/bar/]},
- {-type => name => args => [qw/foo/]},
- ],
+ lhs => $bar,
+ rhs => $foo,
on => {
-type => 'expr',
op => '==',
- args => [
- { -type => 'name', args => [qw/foo id/] },
- { -type => 'name', args => [qw/me foo_id/] },
- ]
+ args => [ $foo_id, $me_foo_id ]
}
}
), "bar JOIN foo ON (foo.id = me.foo_id)",
"simple join clause";
+
+$foo_id = { -type => 'name', args => [qw/foo_id/] };
+
is $sqla->dispatch(
{ -type => 'join',
- args => [
- {-type => name => args => [qw/fnord/]},
- {-type => 'alias', ident => {-type => name => args => [qw/foo/]}, as => 'bar' }
- ],
- using => { -type => 'name', args => [qw/foo_id/] },
+ lhs => $fnord,
+ rhs => {-type => 'alias', ident => $foo, as => 'bar' },
+ using => $foo_id
}
), "fnord JOIN foo AS bar USING (foo_id)",
"using join clause";
is $sqla->dispatch(
{ -type => 'join',
join_type => 'LEFT',
- args => [
- {-type => name => args => [qw/fnord/]},
- {-type => 'alias', ident => {-type => name => args => [qw/foo/]}, as => 'bar' }
- ],
- using => { -type => 'name', args => [qw/foo_id/] },
+ lhs => $fnord,
+ rhs => {-type => 'alias', ident => $foo, as => 'bar' },
+ using => $foo_id
}
), "fnord LEFT JOIN foo AS bar USING (foo_id)",
"using left join clause";
],
tablespec => {
-type => 'join',
- args => [
- {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
- {-type => 'name', args => [qw/bar/] },
- ],
+ lhs => {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
+ rhs => {-type => 'name', args => [qw/bar/] },
on => {
-type => 'expr',
op => '==',