comparison caching-tests/test.ur @ 2225:6262dabc08d6

Simplify example.
author Ziv Scully <ziv@mit.edu>
date Fri, 27 Mar 2015 11:19:15 -0400
parents 278e10629ba1
children 2f7ed04332a0
comparison
equal deleted inserted replaced
2224:5709482a2afd 2225:6262dabc08d6
1 table foo01 : {Id : int, Bar : string} PRIMARY KEY Id
2 table foo10 : {Id : int, Bar : string} PRIMARY KEY Id
3 table tab : {Id : int, Val : int} PRIMARY KEY Id 1 table tab : {Id : int, Val : int} PRIMARY KEY Id
4 2
5 fun cache01 () =
6 res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 43);
7 return <xml><body>
8 Reading 1.
9 {case res of
10 None => <xml>?</xml>
11 | Some row => <xml>{[row.Foo01.Bar]}</xml>}
12 </body></xml>
13
14 (* fun cache10 () = *)
15 (* res <- queryX (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42) *)
16 (* (fn row => <xml>{[row.Foo10.Bar]}</xml>); *)
17 (* return <xml><body> *)
18 (* Reading 2. *)
19 (* {res} *)
20 (* </body></xml> *)
21
22 (* fun cache11 () = *)
23 (* res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42); *)
24 (* bla <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42); *)
25 (* return <xml><body> *)
26 (* Reading 1 and 2. *)
27 (* {case res of *)
28 (* None => <xml>?</xml> *)
29 (* | Some row => <xml>{[row.Foo01.Bar]}</xml>} *)
30 (* {case bla of *)
31 (* None => <xml>?</xml> *)
32 (* | Some row => <xml>{[row.Foo10.Bar]}</xml>} *)
33 (* </body></xml> *)
34
35 fun flush01 () =
36 dml (INSERT INTO foo01 (Id, Bar) VALUES (42, "baz01"));
37 (* dml (UPDATE foo01 SET Bar = "baz01" WHERE Id = 42); *)
38 return <xml><body>
39 Flushed 1!
40 </body></xml>
41
42 (* fun flush10 () = *)
43 (* dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42); *)
44 (* return <xml><body> *)
45 (* Flushed 2! *)
46 (* </body></xml> *)
47
48 (* fun flush11 () = *)
49 (* dml (UPDATE foo01 SET Bar = "baz11" WHERE Id = 42); *)
50 (* dml (UPDATE foo10 SET Bar = "baz11" WHERE Id = 42); *)
51 (* return <xml><body> *)
52 (* Flushed 1 and 2! *)
53 (* </body></xml> *)
54
55 fun cache id = 3 fun cache id =
56 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]}); 4 res <- oneOrNoRows (SELECT tab.Val
5 FROM tab
6 WHERE tab.Id = {[id]});
57 return <xml><body> 7 return <xml><body>
58 Reading {[id]}. 8 Reading {[id]}.
59 {case res of 9 {case res of
60 None => <xml>?</xml> 10 None => <xml>?</xml>
61 | Some row => <xml>{[row.Tab.Val]}</xml>} 11 | Some row => <xml>{[row.Tab.Val]}</xml>}
62 </body></xml> 12 </body></xml>
63 13
64 fun flush id = 14 fun flush id =
65 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]}); 15 res <- oneOrNoRows (SELECT tab.Val
16 FROM tab
17 WHERE tab.Id = {[id]});
66 (case res of 18 (case res of
67 None => dml (INSERT INTO tab (Id, Val) VALUES ({[id]}, 0)) 19 None => dml (INSERT INTO tab (Id, Val)
68 | Some row => dml (UPDATE tab SET Val = {[row.Tab.Val + 1]} WHERE Id = {[id]})); 20 VALUES ({[id]}, 0))
21 | Some row => dml (UPDATE tab
22 SET Val = {[row.Tab.Val + 1]}
23 WHERE Id = {[id]}));
69 return <xml><body> 24 return <xml><body>
70 (* Flushed {[id]}! *)
71 {case res of 25 {case res of
72 None => <xml>Initialized {[id]}!</xml> 26 None => <xml>Initialized {[id]}!</xml>
73 | Some row => <xml>Incremented {[id]}!</xml>} 27 | Some row => <xml>Incremented {[id]}!</xml>}
74 </body></xml> 28 </body></xml>