adamc@991: open Orm
adamc@991: 
adamc@991: structure T = Table(struct
adamc@1093:                         val cols = {A = local [int],
adamc@1093:                                     B = local [string]}
adamc@991:                     end)
adamc@991: 
adamc@991: structure S = Table(struct
adamc@991:                         val cols = {C = T.id,
adamc@1093:                                     D = local [float]}
adamc@991:                     end)
adamc@991: 
adamc@991: fun action () =
adamc@992:     r1 <- T.create {A = 3, B = "Hi"};
adamc@992:     T.save (r1 -- #B ++ {B = "Bye"});
adamc@992:     r2 <- T.create {A = 4, B = "Why"};
adamc@992:     r3 <- T.create {A = 66, B = "Hi"};
adamc@991: 
adamc@992:     s <- S.create {C = r1.Id, D = 45.67};
adamc@991: 
adamc@991:     ls <- T.list;
adamc@991:     ls' <- T.search (T.eq T.cols.B.Col "Hi");
adamc@991: 
adamc@991:     lsS <- S.list;
adamc@991:     lsS <- List.mapM (fn r => p <- S.cols.C.Parent r; return (r, p)) lsS;
adamc@991: 
adamc@992:     T.delete r1;
adamc@992:     T.delete r2;
adamc@992:     T.delete r3;
adamc@992: 
adamc@992:     S.delete s;
adamc@992: 
adamc@991:     return <xml><body>
adamc@991:       {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls}
adamc@991:       <br/>
adamc@991:       {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls'}
adamc@991:       <br/>
adamc@991:       {List.mapX (fn (s, ro) => <xml><li> {[s.D]}: {case ro of
adamc@991:                                                         None => <xml>No parent</xml>
adamc@991:                                                       | Some r => <xml>{[r.B]}</xml>}
adamc@991:       </li></xml>) lsS}
adamc@991:     </body></xml>
adamc@991:     
adamc@991: fun main () = return <xml><body>
adamc@991:   <form><submit action={action}/></form>
adamc@991: </body></xml>