annotate caching-tests/test.ur @ 2221:278e10629ba1

Basic field-resolution invalidation.
author Ziv Scully <ziv@mit.edu>
date Sat, 29 Nov 2014 03:37:59 -0500
parents f7113855f3b7
children 6262dabc08d6
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@2221 14 (* fun cache10 () = *)
ziv@2221 15 (* res <- queryX (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42) *)
ziv@2221 16 (* (fn row => <xml>{[row.Foo10.Bar]}</xml>); *)
ziv@2221 17 (* return <xml><body> *)
ziv@2221 18 (* Reading 2. *)
ziv@2221 19 (* {res} *)
ziv@2221 20 (* </body></xml> *)
ziv@2213 21
ziv@2221 22 (* fun cache11 () = *)
ziv@2221 23 (* res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42); *)
ziv@2221 24 (* bla <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42); *)
ziv@2221 25 (* return <xml><body> *)
ziv@2221 26 (* Reading 1 and 2. *)
ziv@2221 27 (* {case res of *)
ziv@2221 28 (* None => <xml>?</xml> *)
ziv@2221 29 (* | Some row => <xml>{[row.Foo01.Bar]}</xml>} *)
ziv@2221 30 (* {case bla of *)
ziv@2221 31 (* None => <xml>?</xml> *)
ziv@2221 32 (* | Some row => <xml>{[row.Foo10.Bar]}</xml>} *)
ziv@2221 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@2221 42 (* fun flush10 () = *)
ziv@2221 43 (* dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42); *)
ziv@2221 44 (* return <xml><body> *)
ziv@2221 45 (* Flushed 2! *)
ziv@2221 46 (* </body></xml> *)
ziv@2203 47
ziv@2221 48 (* fun flush11 () = *)
ziv@2221 49 (* dml (UPDATE foo01 SET Bar = "baz11" WHERE Id = 42); *)
ziv@2221 50 (* dml (UPDATE foo10 SET Bar = "baz11" WHERE Id = 42); *)
ziv@2221 51 (* return <xml><body> *)
ziv@2221 52 (* Flushed 1 and 2! *)
ziv@2221 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@2221 66 (case res of
ziv@2221 67 None => dml (INSERT INTO tab (Id, Val) VALUES ({[id]}, 0))
ziv@2221 68 | Some row => dml (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>