Mercurial > urweb
annotate demo/refFun.ur @ 569:162d5308e34f
Successfully generated a page element from a signal
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 20 Dec 2008 16:19:26 -0500 |
parents | 7ef4b2911b09 |
children | 1a317a707d71 |
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@471 | 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@471 | 17 o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {[r]}); |
adamc@501 | 18 case o of |
adamc@419 | 19 None => error <xml>You already deleted that ref!</xml> |
adamc@501 | 20 | Some r => return r.T.Data |
adamc@419 | 21 |
adamc@419 | 22 fun write r d = |
adamc@471 | 23 dml (UPDATE t SET Data = {[d]} WHERE Id = {[r]}) |
adamc@419 | 24 |
adamc@419 | 25 fun delete r = |
adamc@471 | 26 dml (DELETE FROM t WHERE Id = {[r]}) |
adamc@420 | 27 |
adamc@419 | 28 end |