view demo/refFun.ur @ 1931:1a04b1edded2

Fix regression in http.c for long-polling connections; add lazy initialization of database connections, to avoid the overhead in handlers that don't use SQL
author Adam Chlipala <adam@chlipala.net>
date Wed, 11 Dec 2013 14:57:54 -0500
parents 1a317a707d71
children
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 }
      PRIMARY KEY Id

    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