view demo/refFun.ur @ 706:1fb318c17546

Enhance table sig item support and get demo compiling again
author Adam Chlipala <adamc@hcoop.net>
date Tue, 07 Apr 2009 15:04:07 -0400
parents 7ef4b2911b09
children 1a317a707d71
line wrap: on
line source
functor Make(M : sig
                 type data
                 val inj : sql_injectable data
             end) = struct

    type ref = int

    sequence s
    table t : { Id : int, Data : M.data }

    fun new d =
        id <- nextval s;
        dml (INSERT INTO t (Id, Data) VALUES ({[id]}, {[d]}));
        return id

    fun read r =
        o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {[r]});
        case o of
            None => error <xml>You already deleted that ref!</xml>
          | Some r => return r.T.Data

    fun write r d =
        dml (UPDATE t SET Data = {[d]} WHERE Id = {[r]})

    fun delete r =
        dml (DELETE FROM t WHERE Id = {[r]})

end