From: Ash Berlin Date: Tue, 3 Mar 2009 09:30:08 +0000 (+0000) Subject: Add IN generator X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d2582f0fd51a3018d8c88739b46efbd3fa76bf64;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Add IN generator --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index d1dc021..5026129 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -183,6 +183,15 @@ class SQL::Abstract { ); } + method _in($ast) { + my (undef, $field, @values) = @$ast; + + return $self->generate($field) . + " IN (" . + join(", ", map { $self->generate($_) } @values ) . + ")"; + } + method _generic_func(ArrayRef $ast) { } diff --git a/t/001_basic.t b/t/001_basic.t index 224c81b..bd6220f 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 15; use Test::Differences; use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); @@ -109,3 +109,21 @@ is $sqla->generate( ] ] ), "WHERE me.id = ? AND (me.name > ? OR me.name < ?)", "where clause"; + +eq_or_diff( + [SQL::Abstract->generate( + [ -where => + [ -in => + [-name => qw/me id/], + [-value => '100' ], + [-value => '200' ], + [-value => '300' ], + ] + ] + ) ], + + [ "WHERE me.id IN (?, ?, ?)", + [ qw/100 200 300/] + ], + + "where IN clause");