comparison demo/more/orm1.ur @ 991:b132f8620a66

Initial Orm1 demo
author Adam Chlipala <adamc@hcoop.net>
date Tue, 06 Oct 2009 10:34:27 -0400
parents
children b825d843b22d
comparison
equal deleted inserted replaced
990:46803e668a89 991:b132f8620a66
1 open Orm
2
3 structure T = Table(struct
4 val cols = {A = local [int] _,
5 B = local [string] _}
6 end)
7
8 structure S = Table(struct
9 val cols = {C = T.id,
10 D = local [float] _}
11 end)
12
13 fun action () =
14 r <- T.create {A = 3, B = "Hi"};
15 T.save (r -- #B ++ {B = "Bye"});
16
17 s <- S.create {C = r.Id, D = 45.67};
18
19 ls <- T.list;
20 ls' <- T.search (T.eq T.cols.B.Col "Hi");
21
22 lsS <- S.list;
23 lsS <- List.mapM (fn r => p <- S.cols.C.Parent r; return (r, p)) lsS;
24
25 return <xml><body>
26 {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls}
27 <br/>
28 {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls'}
29 <br/>
30 {List.mapX (fn (s, ro) => <xml><li> {[s.D]}: {case ro of
31 None => <xml>No parent</xml>
32 | Some r => <xml>{[r.B]}</xml>}
33 </li></xml>) lsS}
34 </body></xml>
35
36 fun main () = return <xml><body>
37 <form><submit action={action}/></form>
38 </body></xml>