# HG changeset patch # User Adam Chlipala # Date 1254839667 14400 # Node ID b132f8620a66def8b6f0ef10b60b3171981f8425 # Parent 46803e668a8970625ba230cb17abaa94a2ef22d2 Initial Orm1 demo diff -r 46803e668a89 -r b132f8620a66 demo/more/orm.ur --- 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) diff -r 46803e668a89 -r b132f8620a66 demo/more/orm.urs --- 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) diff -r 46803e668a89 -r b132f8620a66 demo/more/orm1.ur --- /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 + {List.mapX (fn r =>
  • {[r.A]}: {[r.B]}
  • ) ls} +
    + {List.mapX (fn r =>
  • {[r.A]}: {[r.B]}
  • ) ls'} +
    + {List.mapX (fn (s, ro) =>
  • {[s.D]}: {case ro of + None => No parent + | Some r => {[r.B]}} +
  • ) lsS} +
    + +fun main () = return +
    +
    diff -r 46803e668a89 -r b132f8620a66 demo/more/orm1.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/more/orm1.urp Tue Oct 06 10:34:27 2009 -0400 @@ -0,0 +1,6 @@ +library orm +database dbname=orm1 +sql orm1.sql + +$/list +orm1 diff -r 46803e668a89 -r b132f8620a66 demo/more/orm1.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/more/orm1.urs Tue Oct 06 10:34:27 2009 -0400 @@ -0,0 +1,1 @@ +val main : unit -> transaction page