diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/more/orm1.ur	Tue Oct 06 10:34:27 2009 -0400
@@ -0,0 +1,38 @@
+open Orm
+
+structure T = Table(struct
+                        val cols = {A = local [int] _,
+                                    B = local [string] _}
+                    end)
+
+structure S = Table(struct
+                        val cols = {C = T.id,
+                                    D = local [float] _}
+                    end)
+
+fun action () =
+    r <- T.create {A = 3, B = "Hi"};
+    T.save (r -- #B ++ {B = "Bye"});
+
+    s <- S.create {C = r.Id, D = 45.67};
+
+    ls <- T.list;
+    ls' <- T.search (T.eq T.cols.B.Col "Hi");
+
+    lsS <- S.list;
+    lsS <- List.mapM (fn r => p <- S.cols.C.Parent r; return (r, p)) lsS;
+
+    return <xml><body>
+      {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls}
+      <br/>
+      {List.mapX (fn r => <xml><li> {[r.A]}: {[r.B]}</li></xml>) ls'}
+      <br/>
+      {List.mapX (fn (s, ro) => <xml><li> {[s.D]}: {case ro of
+                                                        None => <xml>No parent</xml>
+                                                      | Some r => <xml>{[r.B]}</xml>}
+      </li></xml>) lsS}
+    </body></xml>
+    
+fun main () = return <xml><body>
+  <form><submit action={action}/></form>
+</body></xml>