Created
November 28, 2012 04:08
-
-
Save db0company/4158975 to your computer and use it in GitHub Desktop.
Error handling with Macaque (Ocsigen)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Lwt_thread = struct | |
include Lwt | |
include Lwt_chan | |
end | |
module Lwt_PGOCaml = PGOCaml_generic.Make Lwt_thread | |
module Lwt_Query = Query.Make_with_Db Lwt_thread Lwt_PGOCaml | |
let get_db : unit -> unit Lwt_PGOCaml.t Lwt.t = | |
let db_handler = ref None in | |
fun () -> | |
match !db_handler with | |
| Some h -> Lwt.return h | |
| None -> Lwt_PGOCaml.connect ~user:login | |
~password:password ~database:dbname () | |
(** Return the result of a macaque query *) | |
let query q = | |
lwt dbh = get_db () in | |
Lwt_Query.query dbh ~log:stderr q | |
let create_user = | |
[...] | |
try (ignore (query q); Success ()) | |
with _ -> Failure [...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment