Skip to content

Instantly share code, notes, and snippets.

@tjdevries
Created May 3, 2023 02:45
Show Gist options
  • Save tjdevries/2ddb78e0317435f56e1deaf15595d920 to your computer and use it in GitHub Desktop.
Save tjdevries/2ddb78e0317435f56e1deaf15595d920 to your computer and use it in GitHub Desktop.
(* create a module hiding implementation of what type the ID is and creating ser/de methods *)
module UserID = struct
type t = int
let t =
let encode (t : t) : (int, string) result = Ok t in
let decode (t : int) : (t, string) result = Ok t in
Caqti_type.(custom ~encode ~decode int)
;;
let mk (t : int) : t = t
end
(* assert that UserID matches the signature for Rapper.CUSTOM *)
module _ : Rapper.CUSTOM = UserID
(* User module that holds all info for User (interacting with DB) *)
module User = struct
type t =
{ id : UserID.t
; name : string
}
[@@deriving model ~table_name:"users"]
end
(* All of these are generated from my deriving macro that I've been working on *)
let _ = User.create
let _ = User.create_record
let _ = User.read
let _ = User.read_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment