THERE ARE FOUR LIGHTS
[scpubgit/Q-Branch.git] / lib / SQL / Abstract / Reference.pm
index 44ad71c..257fd73 100644 (file)
@@ -371,7 +371,7 @@ Directly appended to the key, remember you need to provide an operator:
 
   # expr
   { id => \[
-        "= seriously(?, ?, ?, ?, ?)",
+        "= seriously(?, ?, ?, ?)",
         "use",
         "-ident",
         "and",
@@ -381,11 +381,11 @@ Directly appended to the key, remember you need to provide an operator:
 
   # aqt
   { -literal =>
-      [ 'id = seriously(?, ?, ?, ?, ?)', 'use', -ident => 'and', '-func' ]
+      [ 'id = seriously(?, ?, ?, ?)', 'use', -ident => 'and', '-func' ]
   }
 
   # query
-  id = seriously(?, ?, ?, ?, ?)
+  id = seriously(?, ?, ?, ?)
   [ 'use', -ident => 'and', '-func' ]
 
 (you may absolutely use this when there's no built-in expression type for
@@ -744,6 +744,31 @@ treated as rows:
   VALUES (?, ?), (?, ?)
   [ 1, 2, 3, 4 ]
 
+=head2 list
+
+Expects a value or an arrayref of values, expands them, and returns just
+the expanded aqt for a single entry or a comma operator for multiple:
+
+  # expr
+  { -list => [ { -ident => 'foo' } ] }
+
+  # aqt
+  { -op => [ ',', { -ident => [ 'foo' ] } ] }
+
+  # query
+  foo
+  []
+
+  # expr
+  { -list => [ { -ident => 'foo' }, { -ident => 'bar' } ] }
+
+  # aqt
+  { -op => [ ',', { -ident => [ 'foo' ] }, { -ident => [ 'bar' ] } ] }
+
+  # query
+  foo, bar
+  []
+
 =head2 between op
 
 The RHS of between must either be a pair of exprs/plain values, or a single
@@ -989,9 +1014,6 @@ an order by direction:
 An insert node accepts an into/target clause, a fields clause, a values/from
 clause, and a returning clause.
 
-Note that there is no clause named insert since into or values could be
-what the user meant by that, and it turned out to just be confusing.
-
 The target clause is expanded with an ident default.
 
 The fields clause is expanded as a list expression if an arrayref, and
@@ -1018,7 +1040,7 @@ The returning clause is expanded as a list expr with an ident default.
               { -bind => [ 'baz', 'argh' ] },
       ] } ] },
       returning => { -op => [ ',', { -ident => [ 'id' ] } ] },
-      target => { -op => [ ',', { -ident => [ 'foo' ] } ] },
+      target => { -ident => [ 'foo' ] },
   } }
 
   # query
@@ -1038,12 +1060,12 @@ The returning clause is expanded as a list expr with an ident default.
               [ ',', { -ident => [ 'bar' ] }, { -ident => [ 'baz' ] } ]
       } ] },
       from => { -select => {
-          from => { -from_list => [ { -ident => [ 'other' ] } ] },
+          from => { -ident => [ 'other' ] },
           select => { -op =>
               [ ',', { -ident => [ 'bar' ] }, { -ident => [ 'baz' ] } ]
           },
       } },
-      target => { -op => [ ',', { -ident => [ 'foo' ] } ] },
+      target => { -ident => [ 'foo' ] },
   } }
 
   # query
@@ -1088,7 +1110,7 @@ The returning clause is expanded as a list expr with an ident default.
               ] },
           ] },
       ] },
-      target => { -from_list => [ { -ident => [ 'foo' ] } ] },
+      target => { -ident => [ 'foo' ] },
       where => { -op => [ 'not', { -ident => [ 'quux' ] } ] },
   } }
 
@@ -1096,4 +1118,34 @@ The returning clause is expanded as a list expr with an ident default.
   UPDATE foo SET bar = ?, baz = baz + ? WHERE (NOT quux) RETURNING id, baz
   [ 3, 1 ]
 
+=head2 delete
+
+delete accepts from/target, where, and returning clauses.
+
+The target clause is expanded with an ident default.
+
+The where clauses is expanded as a normal expr.
+
+The returning clause is expanded as a list expr with an ident default.
+
+  # expr
+  { -delete => {
+      from => 'foo',
+      returning => 'id',
+      where => { bar => { '<' => 10 } },
+  } }
+
+  # aqt
+  { -delete => {
+      returning => { -op => [ ',', { -ident => [ 'id' ] } ] },
+      target => { -op => [ ',', { -ident => [ 'foo' ] } ] },
+      where => { -op =>
+          [ '<', { -ident => [ 'bar' ] }, { -bind => [ 'bar', 10 ] } ]
+      },
+  } }
+
+  # query
+  DELETE FROM foo WHERE bar < ? RETURNING id
+  [ 10 ]
+
 =cut