comparison 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
comparison
equal deleted inserted replaced
341:389399d65331 342:f55034419a07
25 25
26 fun create (inputs : $(mapT2T sndTT M.cols)) = 26 fun create (inputs : $(mapT2T sndTT M.cols)) =
27 id <- nextval seq; 27 id <- nextval seq;
28 () <- dml (insert tab (foldT2R2 [sndTT] [colMeta] 28 () <- dml (insert tab (foldT2R2 [sndTT] [colMeta]
29 [fn cols => $(mapT2T (fn t :: (Type * Type) => 29 [fn cols => $(mapT2T (fn t :: (Type * Type) =>
30 sql_exp [T = [Id = int] ++ mapT2T fstTT M.cols] [] [] t.1) cols)] 30 sql_exp [] [] [] t.1) cols)]
31 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) => 31 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
32 [[nm] ~ rest] => 32 [[nm] ~ rest] =>
33 fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input)) 33 fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input))
34 {} [M.cols] inputs M.cols 34 {} [M.cols] inputs M.cols
35 with #Id = (SQL {id}))); 35 with #Id = (SQL {id})));
36 return <html><body> 36 return <html><body>
37 Inserted with ID {txt _ id}. 37 Inserted with ID {txt _ id}.
38 </body></html> 38 </body></html>
39 39
40 fun save (id : int) _ = 40 fun save (id : int) (inputs : $(mapT2T sndTT M.cols)) =
41 () <- dml (update [mapT2T fstTT M.cols] (foldT2R2 [sndTT] [colMeta]
42 [fn cols => $(mapT2T (fn t :: (Type * Type) =>
43 sql_exp [T = [Id = int] ++ mapT2T fstTT M.cols] [] [] t.1) cols)]
44 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
45 [[nm] ~ rest] =>
46 fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input))
47 {} [M.cols] inputs M.cols)
48 tab (WHERE T.Id = {id}));
41 return <html><body> 49 return <html><body>
42 Under Construction 50 Saved!
43 </body></html> 51 </body></html>
44 52
45 fun update (id : int) = 53 fun update (id : int) =
46 fso <- oneOrNoRows (SELECT tab.{{mapT2T fstTT M.cols}} FROM tab WHERE tab.Id = {id}); 54 fso <- oneOrNoRows (SELECT tab.{{mapT2T fstTT M.cols}} FROM tab WHERE tab.Id = {id});
47 case fso : (Basis.option {Tab : $(mapT2T fstTT M.cols)}) of 55 case fso : (Basis.option {Tab : $(mapT2T fstTT M.cols)}) of