table foo01 : {Id : int, Bar : string} PRIMARY KEY Id
table foo10 : {Id : int, Bar : string} PRIMARY KEY Id
table tab : {Id : int, Val : int} PRIMARY KEY Id
fun cache01 () =
res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
return
Reading 1.
{case res of
None => ?
| Some row => {[row.Foo01.Bar]}}
fun cache10 () =
res <- queryX (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42)
(fn row => {[row.Foo10.Bar]});
return
Reading 2.
{res}
fun cache11 () =
res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
bla <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42);
return
Reading 1 and 2.
{case res of
None => ?
| Some row => {[row.Foo01.Bar]}}
{case bla of
None => ?
| Some row => {[row.Foo10.Bar]}}
fun flush01 () =
dml (UPDATE foo01 SET Bar = "baz01" WHERE Id = 42);
return
Flushed 1!
fun flush10 () =
dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42);
return
Flushed 2!
fun flush11 () =
dml (UPDATE foo01 SET Bar = "baz11" WHERE Id = 42);
dml (UPDATE foo10 SET Bar = "baz11" WHERE Id = 42);
return
Flushed 1 and 2!
fun cache id =
res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
return
Reading {[id]}.
{case res of
None => ?
| Some row => {[row.Tab.Val]}}
fun flush id =
res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
dml (case res of
None => (INSERT INTO tab (Id, Val) VALUES ({[id]}, 0))
| Some row => (UPDATE tab SET Val = {[row.Tab.Val + 1]} WHERE Id = {[id]}));
return
(* Flushed {[id]}! *)
{case res of
None => Initialized {[id]}!
| Some row => Incremented {[id]}!}