annotate demo/refFun.ur @ 420:9119a5920106

Prose for Ref and Metaform
author Adam Chlipala <adamc@hcoop.net>
date Thu, 23 Oct 2008 17:52:04 -0400
parents cb5897276abf
children c471345f5165
rev   line source
adamc@419 1 functor Make(M : sig
adamc@419 2 type data
adamc@419 3 val inj : sql_injectable data
adamc@419 4 end) = struct
adamc@419 5
adamc@419 6 type ref = int
adamc@419 7
adamc@419 8 sequence s
adamc@419 9 table t : { Id : int, Data : M.data }
adamc@419 10
adamc@419 11 fun new d =
adamc@419 12 id <- nextval s;
adamc@419 13 () <- dml (INSERT INTO t (Id, Data) VALUES ({id}, {d}));
adamc@419 14 return id
adamc@419 15
adamc@419 16 fun read r =
adamc@419 17 o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {r});
adamc@419 18 return (case o of
adamc@419 19 None => error <xml>You already deleted that ref!</xml>
adamc@419 20 | Some r => r.T.Data)
adamc@419 21
adamc@419 22 fun write r d =
adamc@419 23 dml (UPDATE t SET Data = {d} WHERE Id = {r})
adamc@419 24
adamc@419 25 fun delete r =
adamc@419 26 dml (DELETE FROM t WHERE Id = {r})
adamc@420 27
adamc@419 28 end