Mercurial > urweb
changeset 991:b132f8620a66
Initial Orm1 demo
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 06 Oct 2009 10:34:27 -0400 |
parents | 46803e668a89 |
children | b825d843b22d |
files | demo/more/orm.ur demo/more/orm.urs demo/more/orm1.ur demo/more/orm1.urp demo/more/orm1.urs |
diffstat | 5 files changed, 51 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/demo/more/orm.ur Tue Oct 06 10:15:26 2009 -0400 +++ b/demo/more/orm.ur Tue Oct 06 10:34:27 2009 -0400 @@ -1,11 +1,14 @@ con link = fn col_parent :: (Type * Type) => col_parent.1 -> transaction (option col_parent.2) -fun noParent [t ::: Type] _ = return None +fun noParent [t ::: Type] (_ : t) = return None con meta = fn col_parent :: (Type * Type) => { Link : link col_parent, Inj : sql_injectable col_parent.1 } +fun local [t :: Type] (inj : sql_injectable t) = {Link = noParent, + Inj = inj} + functor Table(M : sig con cols :: {(Type * Type)} val cols : $(map meta cols)
--- a/demo/more/orm.urs Tue Oct 06 10:15:26 2009 -0400 +++ b/demo/more/orm.urs Tue Oct 06 10:34:27 2009 -0400 @@ -6,6 +6,8 @@ Inj : sql_injectable col_parent.1 } +val local : t :: Type -> sql_injectable t -> meta (t, unit) + functor Table(M : sig con cols :: {(Type * Type)} val cols : $(map meta cols)
--- /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>