changeset 342:f55034419a07

Crud completed
author Adam Chlipala <adamc@hcoop.net>
date Sun, 14 Sep 2008 19:14:40 -0400
parents 389399d65331
children ca98644af384
files lib/basis.urs src/urweb.grm tests/crud.ur
diffstat 3 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lib/basis.urs	Sun Sep 14 19:03:55 2008 -0400
+++ b/lib/basis.urs	Sun Sep 14 19:14:40 2008 -0400
@@ -206,10 +206,10 @@
 val insert : fields ::: {Type}
         -> sql_table fields
         -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc =>
-                [nm = sql_exp [T = fields] [] [] t] ++ acc) [] fields)
+                [nm = sql_exp [] [] [] t] ++ acc) [] fields)
         -> dml
 
-val update : changed ::: {Type} -> unchanged ::: {Type} -> changed ~ unchanged
+val update : changed :: {Type} -> unchanged ::: {Type} -> changed ~ unchanged
         -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc =>
                 [nm = sql_exp [T = changed ++ unchanged] [] [] t] ++ acc) [] changed)
         -> sql_table (changed ++ unchanged)
--- a/src/urweb.grm	Sun Sep 14 19:03:55 2008 -0400
+++ b/src/urweb.grm	Sun Sep 14 19:14:40 2008 -0400
@@ -810,6 +810,7 @@
                                              val loc = s (LPARENleft, RPARENright)
 
                                              val e = (EVar (["Basis"], "update"), loc)
+                                             val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc)
                                              val e = (EApp (e, (ERecord fsets, loc)), loc)
                                              val e = (EApp (e, texp), loc)
                                          in
--- 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) =