diff tests/crud.ur @ 342:f55034419a07

Crud completed
author Adam Chlipala <adamc@hcoop.net>
date Sun, 14 Sep 2008 19:14:40 -0400
parents 389399d65331
children a94a79820d49
line wrap: on
line diff
--- a/tests/crud.ur	Sun Sep 14 19:03:55 2008 -0400
+++ b/tests/crud.ur	Sun Sep 14 19:14:40 2008 -0400
@@ -27,7 +27,7 @@
         id <- nextval seq;
         () <- dml (insert tab (foldT2R2 [sndTT] [colMeta]
                 [fn cols => $(mapT2T (fn t :: (Type * Type) =>
-                        sql_exp [T = [Id = int] ++ mapT2T fstTT M.cols] [] [] t.1) cols)]
+                        sql_exp [] [] [] t.1) cols)]
                 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
                         [[nm] ~ rest] =>
                         fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input))
@@ -37,9 +37,17 @@
                 Inserted with ID {txt _ id}.
         </body></html>
 
-fun save (id : int) _ =
+fun save (id : int) (inputs : $(mapT2T sndTT M.cols)) =
+        () <- dml (update [mapT2T fstTT M.cols] (foldT2R2 [sndTT] [colMeta]
+                [fn cols => $(mapT2T (fn t :: (Type * Type) =>
+                        sql_exp [T = [Id = int] ++ mapT2T fstTT M.cols] [] [] t.1) cols)]
+                (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
+                        [[nm] ~ rest] =>
+                        fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input))
+                {} [M.cols] inputs M.cols)
+                tab (WHERE T.Id = {id}));
         return <html><body>
-                Under Construction
+                Saved!
         </body></html>
 
 fun update (id : int) =