changeset 299:5f6a60b7ab00

Elaborated 'insert'
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Sep 2008 13:47:10 -0400
parents 43f35291433d
children cde1ec47f3af
files lib/basis.urs src/urweb.grm tests/insert.ur tests/insert.urp
diffstat 4 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/basis.urs	Sun Sep 07 13:31:45 2008 -0400
+++ b/lib/basis.urs	Sun Sep 07 13:47:10 2008 -0400
@@ -198,6 +198,28 @@
         -> transaction state
 
 
+(*** Database mutators *)
+
+type dml
+val dml : dml -> transaction unit
+
+val insert : fields ::: {Type}
+        -> sql_table fields
+        -> $fields
+        -> dml
+
+val update : changed ::: {Type} -> unchanged ::: {Type} -> changed ~ unchanged
+        -> sql_table (changed ++ unchanged)
+        -> $changed
+        -> sql_exp [T = changed ++ unchanged] [] [] bool
+        -> dml
+
+val delete : fields ::: {Type}
+        -> sql_table fields
+        -> sql_exp [T = fields] [] [] bool
+        -> dml
+
+
 (** XML *)
 
 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
--- a/src/urweb.grm	Sun Sep 07 13:31:45 2008 -0400
+++ b/src/urweb.grm	Sun Sep 07 13:47:10 2008 -0400
@@ -607,6 +607,14 @@
                                          in
                                              (EApp (e, (EAbs (SYMBOL, NONE, eexp2), loc)), loc)
                                          end)
+       | UNIT LARROW eexp SEMI eexp     (let
+                                             val loc = s (UNITleft, eexp2right)
+                                             val e = (EVar (["Basis"], "bind"), loc)
+                                             val e = (EApp (e, eexp1), loc)
+                                             val t = (TRecord (CRecord [], loc), loc)
+                                         in
+                                             (EApp (e, (EAbs ("_", SOME t, eexp2), loc)), loc)
+                                         end)
        | eexp EQ eexp                   (native_op ("eq", eexp1, eexp2, s (eexp1left, eexp2right)))
        | eexp NE eexp                   (native_op ("ne", eexp1, eexp2, s (eexp1left, eexp2right)))
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insert.ur	Sun Sep 07 13:47:10 2008 -0400
@@ -0,0 +1,5 @@
+table t1 : {A : int, B : string, C : float, D : bool}
+
+fun main () : transaction page =
+        () <- dml (insert t1 {A = 5, B = "6", C = 7.0, D = True});
+        return <html><body>Inserted.</body></html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insert.urp	Sun Sep 07 13:47:10 2008 -0400
@@ -0,0 +1,6 @@
+debug
+database dbname=test
+exe /tmp/webapp
+sql /tmp/urweb.sql
+
+insert