Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
682:5bbb542243e8 | 683:9a2c18dab11d |
---|---|
198 | Some _ => sql_binary sql_eq e1 (sql_inject e2) | 198 | Some _ => sql_binary sql_eq e1 (sql_inject e2) |
199 | 199 |
200 | 200 |
201 functor Broadcast(M : sig type t end) = struct | 201 functor Broadcast(M : sig type t end) = struct |
202 sequence s | 202 sequence s |
203 table t : {Id : int, Client : option client, Channel : option (channel M.t)} | 203 table t : {Id : int, Client : client, Channel : channel M.t} |
204 | 204 |
205 type topic = int | 205 type topic = int |
206 | 206 |
207 val inj : sql_injectable topic = _ | 207 val inj : sql_injectable topic = _ |
208 | 208 |
209 val create = nextval s | 209 val create = nextval s |
210 | |
211 val cleanup = | |
212 dml (DELETE FROM t WHERE Client IS NULL) | |
213 | 210 |
214 fun subscribe id = | 211 fun subscribe id = |
215 cli <- self; | 212 cli <- self; |
216 cleanup; | 213 ro <- oneOrNoRows (SELECT t.Channel FROM t WHERE t.Id = {[id]} AND t.Client = {[cli]}); |
217 ro <- oneOrNoRows (SELECT t.Channel FROM t WHERE t.Id = {[id]} AND t.Client = {[Some cli]}); | |
218 case ro of | 214 case ro of |
219 None => | 215 None => |
220 ch <- channel; | 216 ch <- channel; |
221 dml (INSERT INTO t (Id, Client, Channel) VALUES ({[id]}, {[Some cli]}, {[Some ch]})); | 217 dml (INSERT INTO t (Id, Client, Channel) VALUES ({[id]}, {[cli]}, {[ch]})); |
222 return ch | 218 return ch |
223 | Some r => | 219 | Some r => return r.T.Channel |
224 case r.T.Channel of | |
225 None => error <xml>Broadcast.subscribe: Got null result</xml> | |
226 | Some ch => return ch | |
227 | 220 |
228 fun send id msg = | 221 fun send id msg = |
229 cleanup; | |
230 queryI (SELECT t.Channel FROM t WHERE t.Id = {[id]}) | 222 queryI (SELECT t.Channel FROM t WHERE t.Id = {[id]}) |
231 (fn r => case r.T.Channel of | 223 (fn r => Basis.send r.T.Channel msg) |
232 None => error <xml>Broadcast.send: Got null result</xml> | |
233 | Some ch => Basis.send ch msg) | |
234 end | 224 end |