datatype list t = Nil | Cons of t * list t
table t : {Id : int, A : string}
PRIMARY KEY Id
fun allRows () =
query (SELECT * FROM t)
(fn r acc => return (Cons ((r.T.Id, r.T.A), acc)))
Nil
fun doBatch ls =
case ls of
Nil => return ()
| Cons ((id, a), ls') =>
dml (INSERT INTO t (Id, A) VALUES ({[id]}, {[a]}));
doBatch ls'
fun del id =
dml (DELETE FROM t WHERE t.Id = {[id]})
fun show withDel lss =
let
fun show' ls =
case ls of
Nil =>
| Cons ((id, a), ls) =>
{[id]}
{[a]}
{if withDel then
else
}
{show' ls}
in
Id
A
{show' ls}
}/>
end
fun main () =
lss <- source Nil;
batched <- source Nil;
id <- source "";
a <- source "";
let
fun add () =
id <- get id;
a <- get a;
ls <- get batched;
set batched (Cons ((readError id, a), ls))
fun exec () =
ls <- get batched;
rpc (doBatch ls);
set batched Nil
in
return