summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-09-07 13:47:10 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-09-07 13:47:10 -0400
commit725ce6746ebcd76fc3a8c7aa3248805493d71fa0 (patch)
tree8292403aa4aeb15da4f89189e97210b353704140
parent8443e6fb491fa8c8877e53e6548e2fca401e24d5 (diff)
Elaborated 'insert'
-rw-r--r--lib/basis.urs22
-rw-r--r--src/urweb.grm8
-rw-r--r--tests/insert.ur5
-rw-r--r--tests/insert.urp6
4 files changed, 41 insertions, 0 deletions
diff --git a/lib/basis.urs b/lib/basis.urs
index 3bd2459c..4cd2f6da 100644
--- a/lib/basis.urs
+++ b/lib/basis.urs
@@ -198,6 +198,28 @@ val query : tables ::: {{Type}} -> exps ::: {Type} -> tables ~ exps
-> 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
diff --git a/src/urweb.grm b/src/urweb.grm
index 6cb41890..6f355c43 100644
--- a/src/urweb.grm
+++ b/src/urweb.grm
@@ -607,6 +607,14 @@ eexp : eapps (eapps)
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)))
diff --git a/tests/insert.ur b/tests/insert.ur
new file mode 100644
index 00000000..58db4ef1
--- /dev/null
+++ b/tests/insert.ur
@@ -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>
diff --git a/tests/insert.urp b/tests/insert.urp
new file mode 100644
index 00000000..20d24480
--- /dev/null
+++ b/tests/insert.urp
@@ -0,0 +1,6 @@
+debug
+database dbname=test
+exe /tmp/webapp
+sql /tmp/urweb.sql
+
+insert