aboutsummaryrefslogtreecommitdiffhomepage
path: root/demo
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-03-10 15:17:23 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-03-10 15:17:23 -0400
commitb8e7b835e7cde4cf374138467da8b16e93a65eb9 (patch)
tree433f576bae7ae3c50abfef5327d67f0220601783 /demo
parent4f9024019d78bebec6926d19da0361587c88bd03 (diff)
Batch example
Diffstat (limited to 'demo')
-rw-r--r--demo/batch.ur80
-rw-r--r--demo/batch.urp3
-rw-r--r--demo/batch.urs1
-rw-r--r--demo/increment.urp1
-rw-r--r--demo/prose4
5 files changed, 88 insertions, 1 deletions
diff --git a/demo/batch.ur b/demo/batch.ur
new file mode 100644
index 00000000..454ff691
--- /dev/null
+++ b/demo/batch.ur
@@ -0,0 +1,80 @@
+datatype list t = Nil | Cons of t * list t
+
+table t : {Id : int, A : string}
+
+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 => <xml/>
+ | Cons ((id, a), ls) => <xml>
+ <tr><td>{[id]}</td> <td>{[a]}</td> {if withDel then
+ <xml><td><button value="Delete" onclick={del id}/></td></xml>
+ else
+ <xml/>} </tr>
+ {show' ls}
+ </xml>
+ in
+ <xml><dyn signal={ls <- signal lss; return <xml><table>
+ <tr> <th>Id</th> <th>A</th> </tr>
+ {show' ls}
+ </table></xml>}/></xml>
+ 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;
+
+ doBatch ls;
+ set batched Nil
+ in
+ return <xml><body>
+ <h2>Rows</h2>
+
+ {show True lss}
+
+ <button value="Update" onclick={ls <- allRows (); set lss ls}/><br/>
+ <br/>
+
+ <h2>Batch new rows to add</h2>
+
+ <table>
+ <tr> <th>Id:</th> <td><ctextbox source={id}/></td> </tr>
+ <tr> <th>A:</th> <td><ctextbox source={a}/></td> </tr>
+ <tr> <th/> <td><button value="Batch it" onclick={add ()}/></td> </tr>
+ </table>
+
+ <h2>Already batched:</h2>
+ {show False batched}
+ <button value="Execute" onclick={exec ()}/>
+ </body></xml>
+ end
diff --git a/demo/batch.urp b/demo/batch.urp
new file mode 100644
index 00000000..00a7b25e
--- /dev/null
+++ b/demo/batch.urp
@@ -0,0 +1,3 @@
+database dbname=test
+
+batch
diff --git a/demo/batch.urs b/demo/batch.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/demo/batch.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page
diff --git a/demo/increment.urp b/demo/increment.urp
index 777a6edd..3a5c1073 100644
--- a/demo/increment.urp
+++ b/demo/increment.urp
@@ -1,4 +1,3 @@
database dbname=test
-sql increment.sql
increment
diff --git a/demo/prose b/demo/prose
index 7555b490..dd764ae4 100644
--- a/demo/prose
+++ b/demo/prose
@@ -209,3 +209,7 @@ listEdit.urp
increment.urp
<p>Here's an example where client-side code needs to run more code on the server. We maintain a (server-side) SQL sequence. When the user clicks a button, an AJAX request increments the remote sequence and gets the new value.</p>
+
+batch.urp
+
+<p>This example shows more of what is possible with mixed client/server code. The application is an editor for a simple database table, where additions of new rows can be batched in the client, before a button is clicked to trigger a mass addition.</p>