annotate demo/more/orm1.ur @ 1380:ede95ecb4000

Thanks to Vag Vagoff, catch some cases of an obsolete notation for guarded types in the manual
author Adam Chlipala <adam@chlipala.net>
date Thu, 06 Jan 2011 08:55:53 -0500
parents 8d3aa6c7cee0
children 819756825c8d
rev   line source
adamc@991 1 open Orm
adamc@991 2
adamc@991 3 structure T = Table(struct
adamc@1093 4 val cols = {A = local [int],
adamc@1093 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@1093 10 D = local [float]}
adamc@991 11 end)
adamc@991 12
adamc@991 13 fun action () =
adamc@992 14 r1 <- T.create {A = 3, B = "Hi"};
adamc@992 15 T.save (r1 -- #B ++ {B = "Bye"});
adamc@992 16 r2 <- T.create {A = 4, B = "Why"};
adamc@992 17 r3 <- T.create {A = 66, B = "Hi"};
adamc@991 18
adamc@992 19 s <- S.create {C = r1.Id, D = 45.67};
adamc@991 20
adamc@991 21 ls <- T.list;
adamc@991 22 ls' <- T.search (T.eq T.cols.B.Col "Hi");
adamc@991 23
adamc@991 24 lsS <- S.list;
adamc@991 25 lsS <- List.mapM (fn r => p <- S.cols.C.Parent r; return (r, p)) lsS;
adamc@991 26
adamc@992 27 T.delete r1;
adamc@992 28 T.delete r2;
adamc@992 29 T.delete r3;
adamc@992 30
adamc@992 31 S.delete s;
adamc@992 32
adamc@991 33 return <xml><body>
adamc@991 34 {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls}
adamc@991 35 <br/>
adamc@991 36 {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls'}
adamc@991 37 <br/>
adamc@991 38 {List.mapX (fn (s, ro) => <xml><li> {[s.D]}: {case ro of
adamc@991 39 None => <xml>No parent</xml>
adamc@991 40 | Some r => <xml>{[r.B]}</xml>}
adamc@991 41 </li></xml>) lsS}
adamc@991 42 </body></xml>
adamc@991 43
adamc@991 44 fun main () = return <xml><body>
adamc@991 45 <form><submit action={action}/></form>
adamc@991 46 </body></xml>