comparison lib/ur/top.ur @ 699:4e260887d8f2

Chat demo
author Adam Chlipala <adamc@hcoop.net>
date Sun, 05 Apr 2009 11:48:55 -0400
parents 9a2c18dab11d
children 5c099b1308ae
comparison
equal deleted inserted replaced
698:9b29ce0babb8 699:4e260887d8f2
194 (e1 : sql_exp tables agg exps (option t)) 194 (e1 : sql_exp tables agg exps (option t))
195 (e2 : option t) = 195 (e2 : option t) =
196 case e2 of 196 case e2 of
197 None => (SQL {e1} IS NULL) 197 None => (SQL {e1} IS NULL)
198 | Some _ => sql_binary sql_eq e1 (sql_inject e2) 198 | Some _ => sql_binary sql_eq e1 (sql_inject e2)
199
200
201 functor Broadcast(M : sig type t end) = struct
202 sequence s
203 table t : {Id : int, Client : client, Channel : channel M.t}
204
205 type topic = int
206
207 val inj : sql_injectable topic = _
208
209 val create = nextval s
210
211 fun subscribe id =
212 cli <- self;
213 ro <- oneOrNoRows (SELECT t.Channel FROM t WHERE t.Id = {[id]} AND t.Client = {[cli]});
214 case ro of
215 None =>
216 ch <- channel;
217 dml (INSERT INTO t (Id, Client, Channel) VALUES ({[id]}, {[cli]}, {[ch]}));
218 return ch
219 | Some r => return r.T.Channel
220
221 fun send id msg =
222 queryI (SELECT t.Channel FROM t WHERE t.Id = {[id]})
223 (fn r => Basis.send r.T.Channel msg)
224 end