Commit | Line | Data |
704c5138 |
1 | use strict; |
2 | use warnings; |
3 | |
d0ad3a92 |
4 | use Test::More tests => 4; |
704c5138 |
5 | use Test::Differences; |
6 | |
7 | use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); |
8 | |
9 | my $sqla = SQL::Abstract->create(1); |
10 | |
627dcb62 |
11 | my $foo = {-type => identifier => elements => [qw/foo/]}; |
12 | my $bar = {-type => identifier => elements => [qw/bar/]}, |
13 | my $fnord = {-type => identifier => elements => [qw/fnord/]}; |
f7dc4536 |
14 | |
627dcb62 |
15 | my $foo_id = { -type => 'identifier', elements => [qw/foo id/] }; |
16 | my $me_foo_id = { -type => 'identifier', elements => [qw/me foo_id/] }; |
f7dc4536 |
17 | |
704c5138 |
18 | is $sqla->dispatch( |
cbcfedc1 |
19 | { -type => 'join', |
f7dc4536 |
20 | lhs => $bar, |
21 | rhs => $foo, |
747f7c21 |
22 | on => { |
23 | -type => 'expr', |
24 | op => '==', |
f7dc4536 |
25 | args => [ $foo_id, $me_foo_id ] |
747f7c21 |
26 | } |
cbcfedc1 |
27 | } |
d0ad3a92 |
28 | ), "bar JOIN foo ON (foo.id = me.foo_id)", |
704c5138 |
29 | "simple join clause"; |
30 | |
f7dc4536 |
31 | |
627dcb62 |
32 | $foo_id = { -type => 'identifier', elements => [qw/foo_id/] }; |
f7dc4536 |
33 | |
cbcfedc1 |
34 | is $sqla->dispatch( |
35 | { -type => 'join', |
f7dc4536 |
36 | lhs => $fnord, |
37 | rhs => {-type => 'alias', ident => $foo, as => 'bar' }, |
38 | using => $foo_id |
cbcfedc1 |
39 | } |
d0ad3a92 |
40 | ), "fnord JOIN foo AS bar USING (foo_id)", |
cbcfedc1 |
41 | "using join clause"; |
d0ad3a92 |
42 | |
43 | |
44 | is $sqla->dispatch( |
45 | { -type => 'join', |
46 | join_type => 'LEFT', |
f7dc4536 |
47 | lhs => $fnord, |
48 | rhs => {-type => 'alias', ident => $foo, as => 'bar' }, |
49 | using => $foo_id |
d0ad3a92 |
50 | } |
51 | ), "fnord LEFT JOIN foo AS bar USING (foo_id)", |
52 | "using left join clause"; |