annotate tests/crud.ur @ 325:e457d8972ff1

Crud listing IDs
author Adam Chlipala <adamc@hcoop.net>
date Thu, 11 Sep 2008 17:41:52 -0400
parents
children 950320f33232
rev   line source
adamc@325 1 functor Make(M : sig
adamc@325 2 con cols :: {Type}
adamc@325 3 constraint [Id] ~ cols
adamc@325 4 val tab : sql_table ([Id = int] ++ cols)
adamc@325 5
adamc@325 6 val title : string
adamc@325 7
adamc@325 8 val cols : $(mapTT (fn t => {Show : t -> xbody}) cols)
adamc@325 9 end) = struct
adamc@325 10
adamc@325 11 open constraints M
adamc@325 12 val tab = M.tab
adamc@325 13
adamc@325 14 fun list () =
adamc@325 15 rows <- query (SELECT * FROM tab AS T)
adamc@325 16 (fn fs acc => return <body>
adamc@325 17 {acc} <tr> <td>{txt _ fs.T.Id}</td> </tr>
adamc@325 18 </body>) <body></body>;
adamc@325 19 return <html><head>
adamc@325 20 <title>List</title>
adamc@325 21
adamc@325 22 </head><body>
adamc@325 23
adamc@325 24 <h1>List</h1>
adamc@325 25
adamc@325 26 <table border={1}>
adamc@325 27 <tr> <th>ID</th> </tr>
adamc@325 28 {rows}
adamc@325 29 </table>
adamc@325 30 </body></html>
adamc@325 31
adamc@325 32 fun main () : transaction page = return <html><head>
adamc@325 33 <title>{cdata M.title}</title>
adamc@325 34 </head><body>
adamc@325 35 <h1>{cdata M.title}</h1>
adamc@325 36
adamc@325 37 <li> <a link={list ()}>List all rows</a></li>
adamc@325 38 </body></html>
adamc@325 39
adamc@325 40 end