diff options
Diffstat (limited to 'demo/more')
-rw-r--r-- | demo/more/orm.ur | 5 | ||||
-rw-r--r-- | demo/more/orm.urs | 2 | ||||
-rw-r--r-- | demo/more/orm1.ur | 38 | ||||
-rw-r--r-- | demo/more/orm1.urp | 6 | ||||
-rw-r--r-- | demo/more/orm1.urs | 1 |
5 files changed, 51 insertions, 1 deletions
diff --git a/demo/more/orm.ur b/demo/more/orm.ur index a0fd82a3..24ccac67 100644 --- a/demo/more/orm.ur +++ b/demo/more/orm.ur @@ -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) diff --git a/demo/more/orm.urs b/demo/more/orm.urs index 429d2380..b173d203 100644 --- a/demo/more/orm.urs +++ b/demo/more/orm.urs @@ -6,6 +6,8 @@ con meta = fn col_parent :: (Type * Type) => { 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) diff --git a/demo/more/orm1.ur b/demo/more/orm1.ur new file mode 100644 index 00000000..bdf6ef8c --- /dev/null +++ b/demo/more/orm1.ur @@ -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> diff --git a/demo/more/orm1.urp b/demo/more/orm1.urp new file mode 100644 index 00000000..96d1a6e7 --- /dev/null +++ b/demo/more/orm1.urp @@ -0,0 +1,6 @@ +library orm +database dbname=orm1 +sql orm1.sql + +$/list +orm1 diff --git a/demo/more/orm1.urs b/demo/more/orm1.urs new file mode 100644 index 00000000..6ac44e0b --- /dev/null +++ b/demo/more/orm1.urs @@ -0,0 +1 @@ +val main : unit -> transaction page |