diff lib/ur/top.ur @ 683:9a2c18dab11d

Expunging non-nullable rows
author Adam Chlipala <adamc@hcoop.net>
date Sun, 29 Mar 2009 13:30:01 -0400
parents 5bbb542243e8
children 4e260887d8f2
line wrap: on
line diff
--- a/lib/ur/top.ur	Sun Mar 29 11:37:29 2009 -0400
+++ b/lib/ur/top.ur	Sun Mar 29 13:30:01 2009 -0400
@@ -200,7 +200,7 @@
 
 functor Broadcast(M : sig type t end) = struct
     sequence s
-    table t : {Id : int, Client : option client, Channel : option (channel M.t)}
+    table t : {Id : int, Client : client, Channel : channel M.t}
 
     type topic = int
 
@@ -208,27 +208,17 @@
 
     val create = nextval s
 
-    val cleanup =
-        dml (DELETE FROM t WHERE Client IS NULL)
-
     fun subscribe id =
         cli <- self;
-        cleanup;
-        ro <- oneOrNoRows (SELECT t.Channel FROM t WHERE t.Id = {[id]} AND t.Client = {[Some cli]});
+        ro <- oneOrNoRows (SELECT t.Channel FROM t WHERE t.Id = {[id]} AND t.Client = {[cli]});
         case ro of
             None =>
             ch <- channel;
-            dml (INSERT INTO t (Id, Client, Channel) VALUES ({[id]}, {[Some cli]}, {[Some ch]}));
+            dml (INSERT INTO t (Id, Client, Channel) VALUES ({[id]}, {[cli]}, {[ch]}));
             return ch
-          | Some r =>
-            case r.T.Channel of
-                None => error <xml>Broadcast.subscribe: Got null result</xml>
-              | Some ch => return ch
+          | Some r => return r.T.Channel
 
     fun send id msg =
-        cleanup;
         queryI (SELECT t.Channel FROM t WHERE t.Id = {[id]})
-        (fn r => case r.T.Channel of
-                     None => error <xml>Broadcast.send: Got null result</xml>
-                   | Some ch => Basis.send ch msg)
+        (fn r => Basis.send r.T.Channel msg)
 end