annotate tests/crud.ur @ 332:02d15d81ae9b

foldTRX2
author Adam Chlipala <adamc@hcoop.net>
date Sat, 13 Sep 2008 11:13:46 -0400
parents eec65c11d3e2
children 9601c717d2f3
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@332 23 {foldTRX2 [idT] [colMeta'] [tr]
adamc@329 24 (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
adamc@326 25 [[nm] ~ rest] =>
adamc@332 26 fn v funcs => <tr>
adamc@329 27 <td>{funcs.Show v}</td>
adamc@326 28 </tr>)
adamc@326 29 [M.cols] (fs.T -- #Id) M.cols}
adamc@326 30 </tr>
adamc@325 31 </body>) <body></body>;
adamc@325 32 return <html><head>
adamc@325 33 <title>List</title>
adamc@325 34
adamc@325 35 </head><body>
adamc@325 36
adamc@325 37 <h1>List</h1>
adamc@325 38
adamc@325 39 <table border={1}>
adamc@325 40 <tr> <th>ID</th> </tr>
adamc@325 41 {rows}
adamc@325 42 </table>
adamc@325 43 </body></html>
adamc@325 44
adamc@325 45 fun main () : transaction page = return <html><head>
adamc@325 46 <title>{cdata M.title}</title>
adamc@325 47 </head><body>
adamc@325 48 <h1>{cdata M.title}</h1>
adamc@325 49
adamc@325 50 <li> <a link={list ()}>List all rows</a></li>
adamc@325 51 </body></html>
adamc@325 52
adamc@325 53 end