# HG changeset patch # User Adam Chlipala # Date 1220809630 14400 # Node ID 5f6a60b7ab0084928172c16de297b5b5ee27155d # Parent 43f35291433dc3a5117bf478da7356ea48f271c0 Elaborated 'insert' diff -r 43f35291433d -r 5f6a60b7ab00 lib/basis.urs --- 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 diff -r 43f35291433d -r 5f6a60b7ab00 src/urweb.grm --- 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))) diff -r 43f35291433d -r 5f6a60b7ab00 tests/insert.ur --- /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 Inserted. diff -r 43f35291433d -r 5f6a60b7ab00 tests/insert.urp --- /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