From fe35c44cd34ceb2a2f02b27f56bf1607557bb89a Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 14 Sep 2008 19:03:55 -0400 Subject: Crud update form --- tests/crud.ur | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'tests/crud.ur') diff --git a/tests/crud.ur b/tests/crud.ur index 0a7efeec..66a685bf 100644 --- a/tests/crud.ur +++ b/tests/crud.ur @@ -2,6 +2,7 @@ con colMeta = fn t_formT :: (Type * Type) => { Nam : string, Show : t_formT.1 -> xbody, Widget : nm :: Name -> xml form [] [nm = t_formT.2], + WidgetPopulated : nm :: Name -> t_formT.1 -> xml form [] [nm = t_formT.2], Parse : t_formT.2 -> t_formT.1, Inject : sql_injectable t_formT.1 } @@ -36,6 +37,29 @@ fun create (inputs : $(mapT2T sndTT M.cols)) = Inserted with ID {txt _ id}. +fun save (id : int) _ = + return + Under Construction + + +fun update (id : int) = + fso <- oneOrNoRows (SELECT tab.{{mapT2T fstTT M.cols}} FROM tab WHERE tab.Id = {id}); + case fso : (Basis.option {Tab : $(mapT2T fstTT M.cols)}) of + None => return Not found! + | Some fs => return + {foldT2R2 [fstTT] [colMeta] [fn cols :: {(Type * Type)} => xml form [] (mapT2T sndTT cols)] + (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) => + [[nm] ~ rest] => + fn (v : t.1) (col : colMeta t) (acc : xml form [] (mapT2T sndTT rest)) => +
  • {cdata col.Nam}: {col.WidgetPopulated [nm] v}
  • + {useMore acc} +
    ) + + [M.cols] fs.Tab M.cols} + + +
    + fun delete (id : int) = () <- dml (DELETE FROM tab WHERE Id = {id}); return @@ -60,7 +84,7 @@ fun main () : transaction page = {col.Show v} ) [M.cols] (fs.T -- #Id) M.cols} - [Delete] + [Update] [Delete] ); return -- cgit v1.2.3