From bef4dd04f19c2001561e9e889116f5a2f8905bc0 Mon Sep 17 00:00:00 2001 From: Ziv Scully Date: Fri, 27 Mar 2015 11:19:15 -0400 Subject: Simplify example. --- caching-tests/test.ur | 68 ++++++++------------------------------------------ caching-tests/test.urp | 3 --- caching-tests/test.urs | 6 ----- 3 files changed, 11 insertions(+), 66 deletions(-) (limited to 'caching-tests') diff --git a/caching-tests/test.ur b/caching-tests/test.ur index 2722bcdc..8035e336 100644 --- a/caching-tests/test.ur +++ b/caching-tests/test.ur @@ -1,59 +1,9 @@ -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 = 43); - 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 (INSERT INTO foo01 (Id, Bar) VALUES (42, "baz01")); - (* 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]}); + res <- oneOrNoRows (SELECT tab.Val + FROM tab + WHERE tab.Id = {[id]}); return Reading {[id]}. {case res of @@ -62,12 +12,16 @@ fun cache id = fun flush id = - res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[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]})); + 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 - (* Flushed {[id]}! *) {case res of None => Initialized {[id]}! | Some row => Incremented {[id]}!} diff --git a/caching-tests/test.urp b/caching-tests/test.urp index 7ac469f9..796a6257 100644 --- a/caching-tests/test.urp +++ b/caching-tests/test.urp @@ -1,8 +1,5 @@ database test.db sql test.sql -safeGet Test/flush01 -safeGet Test/flush10 -safeGet Test/flush11 safeGet Test/flush test diff --git a/caching-tests/test.urs b/caching-tests/test.urs index 30bff733..6d4cedf2 100644 --- a/caching-tests/test.urs +++ b/caching-tests/test.urs @@ -1,8 +1,2 @@ -val cache01 : unit -> transaction page -(* val cache10 : unit -> transaction page *) -(* val cache11 : unit -> transaction page *) -val flush01 : unit -> transaction page -(* val flush10 : unit -> transaction page *) -(* val flush11 : unit -> transaction page *) val cache : int -> transaction page val flush : int -> transaction page -- cgit v1.2.3