diff options
Diffstat (limited to 'lib/value/value.ml')
| -rw-r--r-- | lib/value/value.ml | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/value/value.ml b/lib/value/value.ml index 7a3a4c2..7cd0e52 100644 --- a/lib/value/value.ml +++ b/lib/value/value.ml @@ -4,19 +4,19 @@ type value = Model.target Model.Data.any let none : value = Model.Data.any Model.Data.none -let single : ('db, 'ocaml, Model.target) Model.Typ.t * 'ocaml -> value = +let single : ('db, 'ocaml, Model.target) Model.Types.t * 'ocaml -> value = fun data -> Model.Data.any (Model.Data.v data) (** The key of the fields dictionary: an existential pack over the named type of a field, hiding its ['db] and ['ocaml] parameters *) type key = - | Named : ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named -> key + | Named : ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named -> key module Key = struct type t = key - let equal : t -> t -> bool = fun (Named a) (Named b) -> Model.Typ.same a b - let hash : t -> int = fun (Named n) -> Hashtbl.hash (Model.Typ.name n) + let equal : t -> t -> bool = fun (Named a) (Named b) -> Model.Types.same a b + let hash : t -> int = fun (Named n) -> Hashtbl.hash (Model.Types.name n) end module Fields = Hashtbl.Make (Key) @@ -38,25 +38,27 @@ let target : t -> Model.target = fun t -> t.target let id : t -> int64 = fun t -> t.id let add_field : type ocaml. - t -> ('db, ocaml, Model.target) Model.Typ.t Model.Typ.named -> ocaml -> unit - = + t -> + ('db, ocaml, Model.target) Model.Types.t Model.Types.named -> + ocaml -> + unit = fun t ref data -> - let typ = Model.Typ.typ ref in + let typ = Model.Types.typ ref in Fields.replace t.fields (Named ref) (Model.Data.any (Model.Data.v (typ, data))) -let id_ref : Model.target Model.Typ.monoreference Model.Typ.named = - Model.Typ.named ~name:Model.Identifier.id ~typ:Model.Typ.Integer +let id_ref : Model.target Model.Types.monoreference Model.Types.named = + Model.Types.named ~name:Model.Identifier.id ~typ:Model.Types.Integer let get : type ocaml. - t -> ('db, ocaml, Model.target) Model.Typ.t Model.Typ.named -> ocaml = + t -> ('db, ocaml, Model.target) Model.Types.t Model.Types.named -> ocaml = fun t ref -> - match Model.Typ.provably_equal id_ref ref with + match Model.Types.provably_equal id_ref ref with | Some Type.Equal -> Some t.id | None -> ( match Fields.find_opt t.fields (Named ref) with | Some (Model.Data.Any (Model.Data.V (typ, payload))) -> ( - match Model.Typ.eq_ocaml (Model.Typ.typ ref) typ with + match Model.Types.eq_ocaml (Model.Types.typ ref) typ with | Some Type.Equal -> payload | None -> raise Not_found) | _ -> raise Not_found) @@ -86,7 +88,8 @@ let load : Caqti_lwt.connection -> Model.target -> Int64.t -> t Lwt.t = (** Pretty-print the data of a field, whatever its type *) let pp_data : type db ocaml. - Format.formatter -> (db, ocaml, Model.target) Model.Typ.t -> ocaml -> unit = + Format.formatter -> (db, ocaml, Model.target) Model.Types.t -> ocaml -> unit + = fun fmt typ data -> let pp_option pp fmt data = match data with @@ -94,13 +97,13 @@ let pp_data : type db ocaml. | None -> Format.pp_print_string fmt "NULL" in match typ with - | Model.Typ.Text -> + | Model.Types.Text -> pp_option (fun fmt s -> Format.fprintf fmt "%S" s) fmt data - | Model.Typ.Integer -> + | Model.Types.Integer -> pp_option (fun fmt i -> Format.fprintf fmt "%Ld" i) fmt data - | Model.Typ.MonoReference _ -> + | Model.Types.MonoReference _ -> pp_option (fun fmt i -> Format.fprintf fmt "%Ld" i) fmt data - | Model.Typ.MultiReference _ -> + | Model.Types.MultiReference _ -> Format.fprintf fmt "[%a]" (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.pp_print_string fmt ", ") @@ -111,7 +114,7 @@ let pp : Format.formatter -> t -> unit = fun fmt t -> let fields = Fields.fold - (fun (Named named) data acc -> (Model.Typ.name named, data) :: acc) + (fun (Named named) data acc -> (Model.Types.name named, data) :: acc) t.fields [] |> List.sort (fun (n1, _) (n2, _) -> Model.Identifier.compare n1 n2) in |
