Skip to content

Instantly share code, notes, and snippets.

@db0company
Created November 28, 2012 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save db0company/4158975 to your computer and use it in GitHub Desktop.
Save db0company/4158975 to your computer and use it in GitHub Desktop.
Error handling with Macaque (Ocsigen)
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