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@471: dml (INSERT INTO t (Id, Data) VALUES ({[id]}, {[d]})); adamc@419: return id adamc@419: adamc@419: fun read r = adamc@471: o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {[r]}); adamc@501: case o of adamc@419: None => error You already deleted that ref! adamc@501: | Some r => return r.T.Data adamc@419: adamc@419: fun write r d = adamc@471: dml (UPDATE t SET Data = {[d]} WHERE Id = {[r]}) adamc@419: adamc@419: fun delete r = adamc@471: dml (DELETE FROM t WHERE Id = {[r]}) adamc@420: adamc@419: end