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