aboutsummaryrefslogtreecommitdiffhomepage
path: root/caching-tests/test.ur
blob: 8035e3368a994b37069c441de4a052eeba2cebb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
table tab : {Id : int, Val : int} PRIMARY KEY Id

fun cache id =
    res <- oneOrNoRows (SELECT tab.Val
                        FROM tab
                        WHERE tab.Id = {[id]});
    return <xml><body>
      Reading {[id]}.
      {case res of
           None => <xml>?</xml>
         | Some row => <xml>{[row.Tab.Val]}</xml>}
    </body></xml>

fun flush id =
    res <- oneOrNoRows (SELECT tab.Val
                        FROM tab
                        WHERE tab.Id = {[id]});
    (case res of
         None => dml (INSERT INTO tab (Id, Val)
                      VALUES ({[id]}, 0))
       | Some row => dml (UPDATE tab
                          SET Val = {[row.Tab.Val + 1]}
                          WHERE Id = {[id]}));
    return <xml><body>
      {case res of
           None => <xml>Initialized {[id]}!</xml>
         | Some row => <xml>Incremented {[id]}!</xml>}
    </body></xml>