Mercurial > urweb
annotate caching-tests/test.ur @ 2215:639e62ca2530
Mostly finish effectfulness analysis.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Fri, 31 Oct 2014 09:25:03 -0400 |
parents | 365727ff68f4 |
children | f7113855f3b7 |
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@2213 | 6 res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42); |
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@2204 | 36 dml (UPDATE foo01 SET Bar = "baz01" WHERE Id = 42); |
ziv@2204 | 37 return <xml><body> |
ziv@2204 | 38 Flushed 1! |
ziv@2204 | 39 </body></xml> |
ziv@2203 | 40 |
ziv@2213 | 41 fun flush10 () = |
ziv@2204 | 42 dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42); |
ziv@2204 | 43 return <xml><body> |
ziv@2204 | 44 Flushed 2! |
ziv@2204 | 45 </body></xml> |
ziv@2203 | 46 |
ziv@2213 | 47 fun flush11 () = |
ziv@2204 | 48 dml (UPDATE foo01 SET Bar = "baz11" WHERE Id = 42); |
ziv@2204 | 49 dml (UPDATE foo10 SET Bar = "baz11" WHERE Id = 42); |
ziv@2204 | 50 return <xml><body> |
ziv@2204 | 51 Flushed 1 and 2! |
ziv@2204 | 52 </body></xml> |
ziv@2203 | 53 |
ziv@2213 | 54 fun cache id = |
ziv@2213 | 55 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]}); |
ziv@2204 | 56 return <xml><body> |
ziv@2213 | 57 Reading {[id]}. |
ziv@2204 | 58 {case res of |
ziv@2213 | 59 None => <xml>?</xml> |
ziv@2213 | 60 | Some row => <xml>{[row.Tab.Val]}</xml>} |
ziv@2204 | 61 </body></xml> |
ziv@2203 | 62 |
ziv@2213 | 63 fun flush id = |
ziv@2213 | 64 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]}); |
ziv@2213 | 65 dml (case res of |
ziv@2213 | 66 None => (INSERT INTO tab (Id, Val) VALUES ({[id]}, 0)) |
ziv@2213 | 67 | Some row => (UPDATE tab SET Val = {[row.Tab.Val + 1]} WHERE Id = {[id]})); |
ziv@2204 | 68 return <xml><body> |
ziv@2213 | 69 (* Flushed {[id]}! *) |
ziv@2204 | 70 {case res of |
ziv@2213 | 71 None => <xml>Initialized {[id]}!</xml> |
ziv@2213 | 72 | Some row => <xml>Incremented {[id]}!</xml>} |
ziv@2204 | 73 </body></xml> |