diff options
-rw-r--r-- | lib/basis.urs | 4 | ||||
-rw-r--r-- | src/urweb.grm | 1 | ||||
-rw-r--r-- | tests/crud.ur | 14 |
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/basis.urs b/lib/basis.urs index 7fd5dc52..3fe80d38 100644 --- a/lib/basis.urs +++ b/lib/basis.urs @@ -206,10 +206,10 @@ val dml : dml -> transaction unit val insert : fields ::: {Type} -> sql_table fields -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc => - [nm = sql_exp [T = fields] [] [] t] ++ acc) [] fields) + [nm = sql_exp [] [] [] t] ++ acc) [] fields) -> dml -val update : changed ::: {Type} -> unchanged ::: {Type} -> changed ~ unchanged +val update : changed :: {Type} -> unchanged ::: {Type} -> changed ~ unchanged -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc => [nm = sql_exp [T = changed ++ unchanged] [] [] t] ++ acc) [] changed) -> sql_table (changed ++ unchanged) diff --git a/src/urweb.grm b/src/urweb.grm index 8219c35b..9c8c0251 100644 --- a/src/urweb.grm +++ b/src/urweb.grm @@ -810,6 +810,7 @@ eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright)) val loc = s (LPARENleft, RPARENright) val e = (EVar (["Basis"], "update"), loc) + val e = (ECApp (e, (CWild (KRecord (KType, loc), loc), loc)), loc) val e = (EApp (e, (ERecord fsets, loc)), loc) val e = (EApp (e, texp), loc) in diff --git a/tests/crud.ur b/tests/crud.ur index 66a685bf..7944cf6c 100644 --- a/tests/crud.ur +++ b/tests/crud.ur @@ -27,7 +27,7 @@ fun create (inputs : $(mapT2T sndTT M.cols)) = id <- nextval seq; () <- dml (insert tab (foldT2R2 [sndTT] [colMeta] [fn cols => $(mapT2T (fn t :: (Type * Type) => - sql_exp [T = [Id = int] ++ mapT2T fstTT M.cols] [] [] t.1) cols)] + sql_exp [] [] [] t.1) cols)] (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) => [[nm] ~ rest] => fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input)) @@ -37,9 +37,17 @@ fun create (inputs : $(mapT2T sndTT M.cols)) = Inserted with ID {txt _ id}. </body></html> -fun save (id : int) _ = +fun save (id : int) (inputs : $(mapT2T sndTT M.cols)) = + () <- dml (update [mapT2T fstTT M.cols] (foldT2R2 [sndTT] [colMeta] + [fn cols => $(mapT2T (fn t :: (Type * Type) => + sql_exp [T = [Id = int] ++ mapT2T fstTT M.cols] [] [] t.1) cols)] + (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) => + [[nm] ~ rest] => + fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input)) + {} [M.cols] inputs M.cols) + tab (WHERE T.Id = {id})); return <html><body> - Under Construction + Saved! </body></html> fun update (id : int) = |