add prefix unop example, and example for new keyword node type
[scpubgit/Q-Branch.git] / lib / SQL / Abstract / Reference.pm
index ad27a77..adb96df 100644 (file)
@@ -146,7 +146,17 @@ Standard binop:
   bomb.status = ?
   [ 'unexploded' ]
 
-Not:
+
+Prefix unop:
+
+  # expr
+  { -op => [ '-', { -ident => 'foo' } ] }
+
+  # query
+  - foo
+  []
+
+Not as special case parenthesised unop:
 
   # expr
   { -op => [ 'not', { -ident => 'explosive' } ] }
@@ -229,6 +239,15 @@ Comma (use -row for parens):
   VALUES (1, 2), (3, 4)
   []
 
+=head2 keyword
+
+  # expr
+  { -keyword => 'insert_into' }
+
+  # query
+  INSERT INTO
+  []
+
 =head2 statement types
 
 AQT node types are also provided for C<select>, C<insert>, C<update> and
@@ -279,6 +298,19 @@ an expander has been registered for that node type:
   id OP ?
   [ 'value' ]
 
+If the value is undef, attempts to convert equality and like ops to IS NULL,
+and inequality and not like to IS NOT NULL:
+
+  # expr
+  { id => { '!=' => undef } }
+
+  # aqt
+  { -op => [ 'is_not_null', { -ident => [ 'id' ] } ] }
+
+  # query
+  id IS NOT NULL
+  []
+
 =head3 identifier hashpair w/simple value
 
 Equivalent to a hashtriple with an op of '='.
@@ -562,4 +594,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