annotate demo/batch.ur @ 1739:c414850f206f
Add support for -boot flag, which allows in-tree execution of Ur/Web
The boot flag rewrites most hardcoded paths to point to the build
directory, and also forces static compilation. This is convenient
for developing Ur/Web, or if you cannot 'sudo make install' Ur/Web.
The following changes were made:
* Header files were moved to include/urweb instead of include;
this lets FFI users point their C_INCLUDE_PATH at this directory
at write <urweb/urweb.h>. For internal Ur/Web executables,
we simply pass -I$PATH/include/urweb as normal.
* Differentiate between LIB and SRCLIB; SRCLIB is Ur and JavaScript
source files, while LIB is compiled products from libtool. For
in-tree compilation these live in different places.
* No longer reference Config for paths; instead use Settings; these
settings can be changed dynamically by Compiler.enableBoot ()
(TODO: add a disableBoot function.)
* config.h is now generated directly in include/urweb/config.h,
for consistency's sake (especially since it gets installed
along with the rest of the headers!)
* All of the autotools build products got updated.
* The linkStatic field in protocols now only contains the name of the
build product, and not the absolute path.
Future users have to be careful not to reference the Settings files
to early, lest they get an old version (this was the source of two
bugs during development of this patch.)
author |
Edward Z. Yang <ezyang@mit.edu> |
date |
Wed, 02 May 2012 17:17:57 -0400 |
parents |
ed06e25c70ef |
children |
e6bc6bbd7a32 |
rev |
line source |
adamc@649
|
1 datatype list t = Nil | Cons of t * list t
|
adamc@649
|
2
|
adamc@649
|
3 table t : {Id : int, A : string}
|
adamc@708
|
4 PRIMARY KEY Id
|
adamc@649
|
5
|
adamc@649
|
6 fun allRows () =
|
adamc@649
|
7 query (SELECT * FROM t)
|
adamc@649
|
8 (fn r acc => return (Cons ((r.T.Id, r.T.A), acc)))
|
adamc@649
|
9 Nil
|
adamc@649
|
10
|
adamc@649
|
11 fun doBatch ls =
|
adamc@649
|
12 case ls of
|
adamc@649
|
13 Nil => return ()
|
adamc@649
|
14 | Cons ((id, a), ls') =>
|
adamc@649
|
15 dml (INSERT INTO t (Id, A) VALUES ({[id]}, {[a]}));
|
adamc@649
|
16 doBatch ls'
|
adamc@649
|
17
|
adamc@649
|
18 fun del id =
|
adamc@649
|
19 dml (DELETE FROM t WHERE t.Id = {[id]})
|
adamc@649
|
20
|
adamc@649
|
21 fun show withDel lss =
|
adamc@649
|
22 let
|
adamc@649
|
23 fun show' ls =
|
adamc@649
|
24 case ls of
|
adamc@649
|
25 Nil => <xml/>
|
adamc@649
|
26 | Cons ((id, a), ls) => <xml>
|
adamc@649
|
27 <tr><td>{[id]}</td> <td>{[a]}</td> {if withDel then
|
adamc@908
|
28 <xml><td><button value="Delete" onclick={rpc (del id)}/>
|
adamc@908
|
29 </td></xml>
|
adamc@649
|
30 else
|
adamc@649
|
31 <xml/>} </tr>
|
adamc@649
|
32 {show' ls}
|
adamc@649
|
33 </xml>
|
adamc@649
|
34 in
|
adamc@649
|
35 <xml><dyn signal={ls <- signal lss; return <xml><table>
|
adamc@649
|
36 <tr> <th>Id</th> <th>A</th> </tr>
|
adamc@649
|
37 {show' ls}
|
adamc@649
|
38 </table></xml>}/></xml>
|
adamc@649
|
39 end
|
adamc@649
|
40
|
adamc@782
|
41 fun main () =
|
adamc@649
|
42 lss <- source Nil;
|
adamc@649
|
43 batched <- source Nil;
|
adamc@649
|
44
|
adamc@649
|
45 id <- source "";
|
adamc@649
|
46 a <- source "";
|
adamc@649
|
47
|
adamc@649
|
48 let
|
adamc@649
|
49 fun add () =
|
adamc@649
|
50 id <- get id;
|
adamc@649
|
51 a <- get a;
|
adamc@649
|
52 ls <- get batched;
|
adamc@649
|
53
|
adamc@649
|
54 set batched (Cons ((readError id, a), ls))
|
adamc@649
|
55
|
adamc@649
|
56 fun exec () =
|
adamc@649
|
57 ls <- get batched;
|
adamc@649
|
58
|
adamc@908
|
59 rpc (doBatch ls);
|
adamc@649
|
60 set batched Nil
|
adamc@649
|
61 in
|
adamc@649
|
62 return <xml><body>
|
adamc@649
|
63 <h2>Rows</h2>
|
adamc@649
|
64
|
adamc@649
|
65 {show True lss}
|
adamc@649
|
66
|
adamc@908
|
67 <button value="Update" onclick={ls <- rpc (allRows ()); set lss ls}/><br/>
|
adamc@649
|
68 <br/>
|
adamc@649
|
69
|
adamc@649
|
70 <h2>Batch new rows to add</h2>
|
adamc@649
|
71
|
adamc@649
|
72 <table>
|
adamc@649
|
73 <tr> <th>Id:</th> <td><ctextbox source={id}/></td> </tr>
|
adamc@649
|
74 <tr> <th>A:</th> <td><ctextbox source={a}/></td> </tr>
|
adamc@649
|
75 <tr> <th/> <td><button value="Batch it" onclick={add ()}/></td> </tr>
|
adamc@649
|
76 </table>
|
adamc@649
|
77
|
adamc@649
|
78 <h2>Already batched:</h2>
|
adamc@649
|
79 {show False batched}
|
adamc@649
|
80 <button value="Execute" onclick={exec ()}/>
|
adamc@649
|
81 </body></xml>
|
adamc@649
|
82 end
|