# HG changeset patch # User Adam Chlipala # Date 1227195718 18000 # Node ID 12d163bb856f4a707f8140442d07eaaf8d2cd4a0 # Parent cbeb1683dc6ac72aa62bb5fc80717a3dbd125f54 Update Crud demo to use local functions diff -r cbeb1683dc6a -r 12d163bb856f demo/crud.ur --- a/demo/crud.ur Tue Nov 18 13:47:23 2008 -0500 +++ b/demo/crud.ur Thu Nov 20 10:41:58 2008 -0500 @@ -110,59 +110,64 @@ {ls} - and 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 ++ {nm = - @sql_inject col.Inject (col.Parse input)}) - {} [M.cols] inputs M.cols) - tab (WHERE T.Id = {[id]})); - ls <- list (); - return -

Saved!

+ and upd (id : int) = + let + fun save (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 ++ {nm = + @sql_inject col.Inject (col.Parse input)}) + {} [M.cols] inputs M.cols) + tab (WHERE T.Id = {[id]})); + ls <- list (); + return +

Saved!

- {ls} -
+ {ls} +
+ in + 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] (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} - and upd (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] (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} + + + end - -
    - - and delete (id : int) = - dml (DELETE FROM tab WHERE Id = {[id]}); - ls <- list (); - return -

    The deed is done.

    - - {ls} -
    - - and confirm (id : int) = return -

    Are you sure you want to delete ID #{[id]}?

    - -

    I was born sure!

    -
    + and confirm (id : int) = + let + fun delete () = + dml (DELETE FROM tab WHERE Id = {[id]}); + ls <- list (); + return +

    The deed is done.

    + + {ls} +
    + in + return +

    Are you sure you want to delete ID #{[id]}?

    + +

    I was born sure!

    +
    + end and main () = ls <- list ();