ziv@2213: table tab : {Id : int, Val : int} PRIMARY KEY Id
ziv@2203:
ziv@2213: fun cache id =
ziv@2225: res <- oneOrNoRows (SELECT tab.Val
ziv@2225: FROM tab
ziv@2225: WHERE tab.Id = {[id]});
ziv@2204: return
ziv@2213: Reading {[id]}.
ziv@2204: {case res of
ziv@2213: None => ?
ziv@2213: | Some row => {[row.Tab.Val]}}
ziv@2204:
ziv@2203:
ziv@2213: fun flush id =
ziv@2225: res <- oneOrNoRows (SELECT tab.Val
ziv@2225: FROM tab
ziv@2225: WHERE tab.Id = {[id]});
ziv@2221: (case res of
ziv@2225: None => dml (INSERT INTO tab (Id, Val)
ziv@2225: VALUES ({[id]}, 0))
ziv@2225: | Some row => dml (UPDATE tab
ziv@2225: SET Val = {[row.Tab.Val + 1]}
ziv@2225: WHERE Id = {[id]}));
ziv@2204: return
ziv@2204: {case res of
ziv@2213: None => Initialized {[id]}!
ziv@2213: | Some row => Incremented {[id]}!}
ziv@2204: