annotate 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
rev   line source
adamc@991 1 open Orm
adamc@991 2
adamc@991 3 structure T = Table(struct
adamc@991 4 val cols = {A = local [int] _,
adamc@991 5 B = local [string] _}
adamc@991 6 end)
adamc@991 7
adamc@991 8 structure S = Table(struct
adamc@991 9 val cols = {C = T.id,
adamc@991 10 D = local [float] _}
adamc@991 11 end)
adamc@991 12
adamc@991 13 fun action () =
adamc@991 14 r <- T.create {A = 3, B = "Hi"};
adamc@991 15 T.save (r -- #B ++ {B = "Bye"});
adamc@991 16
adamc@991 17 s <- S.create {C = r.Id, D = 45.67};
adamc@991 18
adamc@991 19 ls <- T.list;
adamc@991 20 ls' <- T.search (T.eq T.cols.B.Col "Hi");
adamc@991 21
adamc@991 22 lsS <- S.list;
adamc@991 23 lsS <- List.mapM (fn r => p <- S.cols.C.Parent r; return (r, p)) lsS;
adamc@991 24
adamc@991 25 return <xml><body>
adamc@991 26 {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls}
adamc@991 27 <br/>
adamc@991 28 {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls'}
adamc@991 29 <br/>
adamc@991 30 {List.mapX (fn (s, ro) => <xml><li> {[s.D]}: {case ro of
adamc@991 31 None => <xml>No parent</xml>
adamc@991 32 | Some r => <xml>{[r.B]}</xml>}
adamc@991 33 </li></xml>) lsS}
adamc@991 34 </body></xml>
adamc@991 35
adamc@991 36 fun main () = return <xml><body>
adamc@991 37 <form><submit action={action}/></form>
adamc@991 38 </body></xml>