From: Matt S Trout Date: Sat, 28 Sep 2019 02:11:52 +0000 (+0000) Subject: arrayref expr X-Git-Tag: v2.000000~3^2~106 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=68af9204fe52b5b80730d20ba4b0fef63548afb6;p=dbsrgits%2FSQL-Abstract.git arrayref expr --- diff --git a/lib/SQL/Abstract/Reference.pm b/lib/SQL/Abstract/Reference.pm index ad27a77..6075f4c 100644 --- a/lib/SQL/Abstract/Reference.pm +++ b/lib/SQL/Abstract/Reference.pm @@ -562,4 +562,35 @@ is short hand for: =head2 arrayref expr +An arrayref becomes a C<-or> over its contents. Arrayrefs, hashrefs and +literals are all expanded and added to the clauses of the C<-or>. If the +arrayref contains a scalar it's treated as the key of a hashpair and the +next element as the value. + + # expr + [ { x => 1 }, [ { y => 2 }, { z => 3 } ], 'key', 'value', \"lit()" ] + + # aqt + { -op => [ + 'or', + { -op => [ '=', { -ident => [ 'x' ] }, { -bind => [ 'x', 1 ] } ] }, + { -op => [ + 'or', { + -op => [ '=', { -ident => [ 'y' ] }, { -bind => [ 'y', 2 ] } ] + }, { + -op => [ '=', { -ident => [ 'z' ] }, { -bind => [ 'z', 3 ] } ] + }, + ] }, { -op => + [ + '=', { -ident => [ 'key' ] }, + { -bind => [ 'key', 'value' ] }, + ] + }, + { -literal => [ 'lit()' ] }, + ] } + + # query + ( x = ? OR ( y = ? OR z = ? ) OR key = ? OR lit() ) + [ 1, 2, 3, 'value' ] + =cut