diff --git a/src/pg.ml b/src/pg.ml index 9da8a192..f11bf629 100644 --- a/src/pg.ml +++ b/src/pg.ml @@ -12,11 +12,14 @@ module Caqti_type = struct let amount : Amount.t t = let open Amount in - custom - ~encode:(fun amount -> Ok (amount.value, amount.fraction)) - ~decode:(fun (value, fraction) -> - Amount.make ~sign:None ~currency:Config.currency ~value ~fraction) - (t2 int64 int32) + let intro value fraction = + match make ~sign:None ~currency:Config.currency ~value ~fraction with + | Error e -> raise (Caqti_type.Reject e) + | Ok v -> v + in + let p1 t = t.value in + let p2 t = t.fraction in + product intro @@ proj int64 p1 @@ proj int32 p2 @@ proj_end let age_mask : int t = Caqti_type.int