wip pg.ml
This commit is contained in:
parent
c48892ca9a
commit
997a579bc8
1 changed files with 53 additions and 0 deletions
53
src/pg.ml
Normal file
53
src/pg.ml
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
(* TODO be sure to not use postgres ptime
|
||||||
|
add a dune stanza like for prelude:
|
||||||
|
"(flags (:standard -open Prelude))" *)
|
||||||
|
module Caqti_type = struct
|
||||||
|
include Caqti_type
|
||||||
|
|
||||||
|
let ptime_to_int64 ptime =
|
||||||
|
ptime |> Ptime.to_float_s |> Int64.of_float |> Result.ok
|
||||||
|
|
||||||
|
let ptime_of_int64 i =
|
||||||
|
match Ptime.of_float_s (Int64.to_float i) with
|
||||||
|
| None -> Fmt.error "ptime_of_int64 error: `%Ld` is not a valid ptime" i
|
||||||
|
| Some ts -> Ok ts
|
||||||
|
|
||||||
|
(* we want to use int64 timestamps,
|
||||||
|
not postgresql built-in timestamp type *)
|
||||||
|
let ptime : Ptime.t Caqti_type.t =
|
||||||
|
Caqti_type.custom ~encode:ptime_to_int64 ~decode:ptime_of_int64
|
||||||
|
Caqti_type.(int64)
|
||||||
|
end
|
||||||
|
|
||||||
|
let pg_amount : Amount.t Caqti_type.t =
|
||||||
|
let open Amount in
|
||||||
|
(* TODO bad int32 conversion *)
|
||||||
|
Caqti_type.custom
|
||||||
|
~encode:(fun amount -> Ok (amount.value, Int64.to_int32 amount.fraction))
|
||||||
|
~decode:(fun (value, fraction) ->
|
||||||
|
let fraction = Int64.of_int32 fraction in
|
||||||
|
Ok { sign= None; currency= `Eur; value; fraction })
|
||||||
|
Caqti_type.(t2 int64 int32)
|
||||||
|
|
||||||
|
(* WIP: minimum db functions for basic /management *)
|
||||||
|
|
||||||
|
let pg_todo () = assert false
|
||||||
|
|
||||||
|
(* signkey *)
|
||||||
|
let activate_signing_key = pg_todo
|
||||||
|
let lookup_signing_key = pg_todo
|
||||||
|
let iterate_active_signkeys = pg_todo
|
||||||
|
let insert_signkey_revocation = pg_todo
|
||||||
|
let lookup_signkey_revocation = pg_todo
|
||||||
|
|
||||||
|
(* denominations *)
|
||||||
|
let insert_denomination_info = pg_todo
|
||||||
|
let get_denomination_info = pg_todo
|
||||||
|
let get_denomination_by_serial = pg_todo
|
||||||
|
let iterate_denomination_info = pg_todo
|
||||||
|
let iterate_denominations = pg_todo
|
||||||
|
let get_coin_denomination = pg_todo
|
||||||
|
let insert_denomination_revocation = pg_todo
|
||||||
|
let get_denomination_revocation = pg_todo
|
||||||
|
let lookup_denomination_key = pg_todo
|
||||||
|
let add_denomination_key = pg_todo
|
||||||
Loading…
Add table
Add a link
Reference in a new issue