adamc@419: functor Make(M : sig adamc@419: type data adamc@419: val inj : sql_injectable data adamc@419: end) = struct adamc@419: adamc@419: type ref = int adamc@419: adamc@419: sequence s adamc@419: table t : { Id : int, Data : M.data } adamc@419: adamc@419: fun new d = adamc@419: id <- nextval s; adamc@419: () <- dml (INSERT INTO t (Id, Data) VALUES ({id}, {d})); adamc@419: return id adamc@419: adamc@419: fun read r = adamc@419: o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {r}); adamc@419: return (case o of adamc@419: None => error You already deleted that ref! adamc@419: | Some r => r.T.Data) adamc@419: adamc@419: fun write r d = adamc@419: dml (UPDATE t SET Data = {d} WHERE Id = {r}) adamc@419: adamc@419: fun delete r = adamc@419: dml (DELETE FROM t WHERE Id = {r}) adamc@420: adamc@419: end