61b57d0626721e194e2f585f71f758e4f2ed49d5
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 201_select.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 3;
5 use Test::Differences;
6
7 use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
8
9 my $sqla = SQL::Abstract->create(1);
10
11 is $sqla->dispatch(
12   { -type => 'select',
13     tablespec => {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
14     columns => [
15       { -type => 'name', args => [qw/me id/] },
16       { -type => 'alias', ident => { -type => 'name', args => [qw/me foo_id/] }, as => 'foo' },
17     ]
18   }
19 ), "SELECT me.id, me.foo_id AS foo FROM foo AS me",
20    "simple select clause";
21
22 __END__
23 is $sqla->dispatch(
24   { -type => 'select',
25     tablespec => {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
26     columns => [
27       { -type => 'name', args => [qw/me id/] },
28       { -type => 'alias', ident => { -type => 'name', args => [qw/me foo_id/] }, as => 'foo' },
29       { -type => 'name', args => [qw/bar name/] },
30     ]
31   }
32
33
34   { -type => 'select',
35     from => [-alias => [-name => 'foo'] => 'me' ],
36     columns => [ -list => 
37         [ -name => qw/me id/ ],
38         [ -alias => [ -name => qw/me foo_id/ ], 'foo' ],
39         [ -name => qw/bar name/ ],
40     ],
41     join => {
42       tablespec => [-name => qw/bar/],
43       on => [ '==', [-name => qw/bar id/], [ -name => qw/me bar_id/ ] ],
44     }
45   }
46 ), "SELECT me.id, me.foo_id AS foo, bar.name FROM foo AS me JOIN bar ON (bar.id = me.bar_id)", 
47    "select with join clause";
48
49