From: Matt S Trout Date: Fri, 12 Apr 2019 20:50:38 +0000 (+0000) Subject: clauses test (xt/ because extra deps) X-Git-Tag: v1.90_01~229 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c42752fcff779da7a99e168ad5b06bbbf0479cc2;p=dbsrgits%2FSQL-Abstract.git clauses test (xt/ because extra deps) --- diff --git a/xt/clauses.t b/xt/clauses.t new file mode 100644 index 0000000..1c88964 --- /dev/null +++ b/xt/clauses.t @@ -0,0 +1,33 @@ +use strict; +use warnings; +use Test::More; +use SQL::Abstract::Test import => [ qw(is_same_sql_bind) ]; +use SQL::Abstract::ExtraClauses; + +my $sqlac = SQL::Abstract::ExtraClauses->new; + +my ($sql, @bind) = $sqlac->select({ + select => [ qw(artist.id artist.name), { -func => [ json_agg => 'cd' ] } ], + from => [ + artist => -join => [ cd => on => { 'cd.artist_id' => 'artist.id' } ], + ], + where => { 'artist.genres', => { '@>', { -value => [ 'Rock' ] } } }, + order_by => 'artist.name', + group_by => 'artist.id', + having => { '>' => [ { -func => [ count => 'cd.id' ] }, 3 ] } +}); + +is_same_sql_bind( + $sql, \@bind, + q{ + SELECT artist.id, artist.name, JSON_AGG(cd) + FROM artist JOIN cd ON cd.artist_id = artist.id + WHERE artist.genres @> ? + ORDER BY artist.name + GROUP BY artist.id + HAVING COUNT(cd.id) > ? + }, + [ [ 'Rock' ], 3 ] +); + +done_testing;