annotate tests/crud.ur @ 329:eec65c11d3e2

foldTR2
author Adam Chlipala <adamc@hcoop.net>
date Sat, 13 Sep 2008 10:30:45 -0400
parents 3a57f3b3a3f8
children 02d15d81ae9b
rev   line source
adamc@329 1 con colMeta' = fn t :: Type => {Show : t -> xbody}
adamc@329 2 con colMeta = fn cols :: {Type} => $(Top.mapTT colMeta' cols)
adamc@326 3
adamc@325 4 functor Make(M : sig
adamc@325 5 con cols :: {Type}
adamc@325 6 constraint [Id] ~ cols
adamc@325 7 val tab : sql_table ([Id = int] ++ cols)
adamc@325 8
adamc@325 9 val title : string
adamc@325 10
adamc@327 11 val cols : colMeta cols
adamc@325 12 end) = struct
adamc@325 13
adamc@325 14 open constraints M
adamc@325 15 val tab = M.tab
adamc@325 16
adamc@325 17 fun list () =
adamc@325 18 rows <- query (SELECT * FROM tab AS T)
adamc@329 19 (fn (fs : {T : $([Id = int] ++ M.cols)}) acc => return <body>
adamc@326 20 {acc}
adamc@326 21 <tr>
adamc@326 22 <td>{txt _ fs.T.Id}</td>
adamc@329 23 {foldTR2 [idT] [colMeta'] [fn _ => xtr]
adamc@329 24 (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
adamc@326 25 [[nm] ~ rest] =>
adamc@329 26 fn v funcs acc =>
adamc@326 27 <tr>
adamc@329 28 <td>{funcs.Show v}</td>
adamc@329 29 {acc}
adamc@326 30 </tr>)
adamc@329 31 <tr></tr>
adamc@326 32 [M.cols] (fs.T -- #Id) M.cols}
adamc@326 33 </tr>
adamc@325 34 </body>) <body></body>;
adamc@325 35 return <html><head>
adamc@325 36 <title>List</title>
adamc@325 37
adamc@325 38 </head><body>
adamc@325 39
adamc@325 40 <h1>List</h1>
adamc@325 41
adamc@325 42 <table border={1}>
adamc@325 43 <tr> <th>ID</th> </tr>
adamc@325 44 {rows}
adamc@325 45 </table>
adamc@325 46 </body></html>
adamc@325 47
adamc@325 48 fun main () : transaction page = return <html><head>
adamc@325 49 <title>{cdata M.title}</title>
adamc@325 50 </head><body>
adamc@325 51 <h1>{cdata M.title}</h1>
adamc@325 52
adamc@325 53 <li> <a link={list ()}>List all rows</a></li>
adamc@325 54 </body></html>
adamc@325 55
adamc@325 56 end