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