From: Matt S Trout Date: Sat, 28 Sep 2019 02:11:52 +0000 (+0000) Subject: arrayref expr X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=24479414b207dfb118a9704920191324e5da2a32;p=scpubgit%2FQ-Branch.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