annotate tests/crud.ur @ 334:9601c717d2f3

queryX
author Adam Chlipala <adamc@hcoop.net>
date Sat, 13 Sep 2008 19:49:53 -0400
parents 02d15d81ae9b
children 34847732cefc
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@334 17 fun main () : transaction page =
adamc@334 18 rows <- queryX (SELECT * FROM tab AS T)
adamc@334 19 (fn (fs : {T : $([Id = int] ++ M.cols)}) => <body>
adamc@326 20 <tr>
adamc@326 21 <td>{txt _ fs.T.Id}</td>
adamc@332 22 {foldTRX2 [idT] [colMeta'] [tr]
adamc@329 23 (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
adamc@326 24 [[nm] ~ rest] =>
adamc@332 25 fn v funcs => <tr>
adamc@329 26 <td>{funcs.Show v}</td>
adamc@326 27 </tr>)
adamc@326 28 [M.cols] (fs.T -- #Id) M.cols}
adamc@326 29 </tr>
adamc@334 30 </body>);
adamc@325 31 return <html><head>
adamc@334 32 <title>{cdata M.title}</title>
adamc@325 33
adamc@325 34 </head><body>
adamc@325 35
adamc@334 36 <h1>{cdata M.title}</h1>
adamc@325 37
adamc@325 38 <table border={1}>
adamc@325 39 <tr> <th>ID</th> </tr>
adamc@325 40 {rows}
adamc@325 41 </table>
adamc@325 42 </body></html>
adamc@325 43
adamc@325 44 end