# HG changeset patch # User Adam Chlipala # Date 1221434080 14400 # Node ID f55034419a07ce68fa421b9826609f5b00defb19 # Parent 389399d65331bff4eec36afcd5fb549b77116049 Crud completed diff -r 389399d65331 -r f55034419a07 lib/basis.urs --- 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) diff -r 389399d65331 -r f55034419a07 src/urweb.grm --- 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 diff -r 389399d65331 -r f55034419a07 tests/crud.ur --- 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}. -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 - Under Construction + Saved! fun update (id : int) =