summaryrefslogtreecommitdiff
path: root/tests/crud.ur
blob: 7f0fc71c77f8f778cd856a56e067c47d9b7885f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
con colMeta' = fn t :: Type => {Show : t -> xbody}
con colMeta = fn cols :: {Type} => $(Top.mapTT colMeta' cols)

functor Make(M : sig
        con cols :: {Type}
        constraint [Id] ~ cols
        val tab : sql_table ([Id = int] ++ cols)

        val title : string

        val cols : colMeta cols
end) = struct

open constraints M
val tab = M.tab

fun main () : transaction page =
        rows <- queryX (SELECT * FROM tab AS T)
                (fn (fs : {T : $([Id = int] ++ M.cols)}) => <body>
                        <tr>
                                <td>{txt _ fs.T.Id}</td>
                                {foldTRX2 [idT] [colMeta'] [tr]
                                        (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
                                                [[nm] ~ rest] =>
                                                fn v funcs => <tr>
                                                        <td>{funcs.Show v}</td>
                                                </tr>)
                                        [M.cols] (fs.T -- #Id) M.cols}
                        </tr>
                </body>);
        return <html><head>
                <title>{cdata M.title}</title>

                </head><body>

                <h1>{cdata M.title}</h1>

                <table border={1}>
                <tr> <th>ID</th> </tr>
                {rows}
                </table>
        </body></html>

end