annotate caching-tests/test.ur @ 2218:f7113855f3b7

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