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