diff sql.ur @ 26:c1da0e3749b3

Sql.listify
author Adam Chlipala <adam@chlipala.net>
date Sun, 13 May 2012 14:13:18 -0400
parents 875221eee987
children
line wrap: on
line diff
--- a/sql.ur	Sun May 06 15:16:27 2012 -0400
+++ b/sql.ur	Sun May 13 14:13:18 2012 -0400
@@ -60,3 +60,16 @@
       oneOrNoRows1 (SELECT t.{{otherCols}}
                     FROM t
                     WHERE {@selector [#T] ! kfl kinj (vs --- _)})
+
+fun listify [lead :: Name] [cols ::: {Type}] [rest ::: {{Type}}] [[lead] ~ rest]
+    (fl : folder cols) (eqs : $(map eq cols)) (q : sql_query [] [] ([lead = cols] ++ rest) []) =
+    query q
+    (fn r acc =>
+        return (case acc of
+                    [] => (r.lead, (r -- lead) :: []) :: []
+                  | (key, ls) :: acc' =>
+                    if @Record.equal eqs fl r.lead key then
+                        (key, (r -- lead) :: ls) :: acc'
+                    else
+                        (r.lead, (r -- lead) :: []) :: acc))
+    []