clauses test (xt/ because extra deps)
[scpubgit/Q-Branch.git] / xt / clauses.t
CommitLineData
c42752fc 1use strict;
2use warnings;
3use Test::More;
4use SQL::Abstract::Test import => [ qw(is_same_sql_bind) ];
5use SQL::Abstract::ExtraClauses;
6
7my $sqlac = SQL::Abstract::ExtraClauses->new;
8
9my ($sql, @bind) = $sqlac->select({
10 select => [ qw(artist.id artist.name), { -func => [ json_agg => 'cd' ] } ],
11 from => [
12 artist => -join => [ cd => on => { 'cd.artist_id' => 'artist.id' } ],
13 ],
14 where => { 'artist.genres', => { '@>', { -value => [ 'Rock' ] } } },
15 order_by => 'artist.name',
16 group_by => 'artist.id',
17 having => { '>' => [ { -func => [ count => 'cd.id' ] }, 3 ] }
18});
19
20is_same_sql_bind(
21 $sql, \@bind,
22 q{
23 SELECT artist.id, artist.name, JSON_AGG(cd)
24 FROM artist JOIN cd ON cd.artist_id = artist.id
25 WHERE artist.genres @> ?
26 ORDER BY artist.name
27 GROUP BY artist.id
28 HAVING COUNT(cd.id) > ?
29 },
30 [ [ 'Rock' ], 3 ]
31);
32
33done_testing;