From 79edb644cdc9c2218be3c34151eb69a84fb8344e Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 6 Oct 2009 10:34:27 -0400 Subject: Initial Orm1 demo --- demo/more/orm.ur | 5 ++++- demo/more/orm.urs | 2 ++ demo/more/orm1.ur | 38 ++++++++++++++++++++++++++++++++++++++ demo/more/orm1.urp | 6 ++++++ demo/more/orm1.urs | 1 + 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 demo/more/orm1.ur create mode 100644 demo/more/orm1.urp create mode 100644 demo/more/orm1.urs (limited to 'demo/more') 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 + {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 --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 -- cgit v1.2.3