annotate caching-tests/test.ur @ 2273:a3cac6cea625

Consildation of caches understands sqlification.
author Ziv Scully <ziv@mit.edu>
date Wed, 04 Nov 2015 20:12:07 -0500
parents f7bc7c11a656
children ce96e166d938
rev   line source
ziv@2213 1 table tab : {Id : int, Val : int} PRIMARY KEY Id
ziv@2203 2
ziv@2213 3 fun cache id =
ziv@2225 4 res <- oneOrNoRows (SELECT tab.Val
ziv@2225 5 FROM tab
ziv@2225 6 WHERE tab.Id = {[id]});
ziv@2204 7 return <xml><body>
ziv@2213 8 Reading {[id]}.
ziv@2204 9 {case res of
ziv@2213 10 None => <xml>?</xml>
ziv@2213 11 | Some row => <xml>{[row.Tab.Val]}</xml>}
ziv@2204 12 </body></xml>
ziv@2203 13
ziv@2273 14 (* fun cache2 id v = *)
ziv@2273 15 (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2273 16 (* FROM tab *)
ziv@2273 17 (* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *)
ziv@2273 18 (* return <xml><body> *)
ziv@2273 19 (* Reading {[id]}. *)
ziv@2273 20 (* {case res of *)
ziv@2273 21 (* None => <xml>Nope, that's not it.</xml> *)
ziv@2273 22 (* | Some _ => <xml>Hooray! You guessed it!</xml>} *)
ziv@2273 23 (* </body></xml> *)
ziv@2273 24
ziv@2273 25 fun cache2 id1 id2 =
ziv@2273 26 res1 <- oneOrNoRows (SELECT tab.Val
ziv@2273 27 FROM tab
ziv@2273 28 WHERE tab.Id = {[id1]});
ziv@2273 29 res2 <- oneOrNoRows (SELECT tab.Val
ziv@2273 30 FROM tab
ziv@2273 31 WHERE tab.Id = {[id2]});
ziv@2269 32 return <xml><body>
ziv@2273 33 Reading {[id1]} and {[id2]}.
ziv@2273 34 {case (res1, res2) of
ziv@2273 35 (Some _, Some _) => <xml>Both are there.</xml>
ziv@2273 36 | _ => <xml>One of them is missing.</xml>}
ziv@2269 37 </body></xml>
ziv@2269 38
ziv@2213 39 fun flush id =
ziv@2239 40 dml (UPDATE tab
ziv@2239 41 SET Val = Val * (Id + 2) / Val - 3
ziv@2239 42 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
ziv@2204 43 return <xml><body>
ziv@2235 44 Changed {[id]}!
ziv@2204 45 </body></xml>
ziv@2234 46
ziv@2242 47 val flush17 =
ziv@2242 48 dml (UPDATE tab
ziv@2242 49 SET Val = Val * (Id + 2) / Val - 3
ziv@2242 50 WHERE Id = 17);
ziv@2242 51 return <xml><body>
ziv@2242 52 Changed specifically 17!
ziv@2242 53 </body></xml>
ziv@2242 54
ziv@2235 55 (* fun flush id = *)
ziv@2235 56 (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2235 57 (* FROM tab *)
ziv@2235 58 (* WHERE tab.Id = {[id]}); *)
ziv@2235 59 (* (case res of *)
ziv@2235 60 (* None => dml (INSERT INTO tab (Id, Val) *)
ziv@2235 61 (* VALUES ({[id]}, 0)) *)
ziv@2235 62 (* | Some row => dml (UPDATE tab *)
ziv@2235 63 (* SET Val = {[row.Tab.Val + 1]} *)
ziv@2235 64 (* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
ziv@2235 65 (* return <xml><body> *)
ziv@2235 66 (* {case res of *)
ziv@2235 67 (* None => <xml>Initialized {[id]}!</xml> *)
ziv@2235 68 (* | Some row => <xml>Incremented {[id]}!</xml>} *)
ziv@2235 69 (* </body></xml> *)