comparison tests/crud.ur @ 326:950320f33232

Crud list works
author Adam Chlipala <adamc@hcoop.net>
date Thu, 11 Sep 2008 18:32:41 -0400
parents e457d8972ff1
children 3a57f3b3a3f8
comparison
equal deleted inserted replaced
325:e457d8972ff1 326:950320f33232
1 con colMeta = fn cols :: {Type} => $(Top.mapTT (fn t => {Show : t -> xbody}) cols)
2
1 functor Make(M : sig 3 functor Make(M : sig
2 con cols :: {Type} 4 con cols :: {Type}
3 constraint [Id] ~ cols 5 constraint [Id] ~ cols
4 val tab : sql_table ([Id = int] ++ cols) 6 val tab : sql_table ([Id = int] ++ cols)
5 7
6 val title : string 8 val title : string
7 9
8 val cols : $(mapTT (fn t => {Show : t -> xbody}) cols) 10 val cols : $(Top.mapTT (fn t => {Show : t -> xbody}) cols)
9 end) = struct 11 end) = struct
10 12
11 open constraints M 13 open constraints M
12 val tab = M.tab 14 val tab = M.tab
13 15
14 fun list () = 16 fun list () =
15 rows <- query (SELECT * FROM tab AS T) 17 rows <- query (SELECT * FROM tab AS T)
16 (fn fs acc => return <body> 18 (fn fs acc => return <body>
17 {acc} <tr> <td>{txt _ fs.T.Id}</td> </tr> 19 {acc}
20 <tr>
21 <td>{txt _ fs.T.Id}</td>
22 {fold [fn cols :: {Type} => $cols -> colMeta cols -> xtr]
23 (fn (nm :: Name) (t :: Type) (rest :: {Type}) acc =>
24 [[nm] ~ rest] =>
25 fn (r : $([nm = t] ++ rest)) cols =>
26 <tr>
27 <td>{cols.nm.Show r.nm}</td>
28 {acc (r -- nm) (cols -- nm)}
29 </tr>)
30 (fn _ _ => <tr></tr>)
31 [M.cols] (fs.T -- #Id) M.cols}
32 </tr>
18 </body>) <body></body>; 33 </body>) <body></body>;
19 return <html><head> 34 return <html><head>
20 <title>List</title> 35 <title>List</title>
21 36
22 </head><body> 37 </head><body>