From bc78bea63b7c75e8a9d222dc86fb75ed293a2242 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 21 Nov 2026 12:22:50 +0100 Subject: Renamed the module Typ into Types --- lib/value/value.ml | 39 +++++++++++++++++++++------------------ lib/value/value.mli | 16 +++++++++------- 2 files changed, 30 insertions(+), 25 deletions(-) (limited to 'lib/value') 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 diff --git a/lib/value/value.mli b/lib/value/value.mli index 9ebbca6..eb03965 100644 --- a/lib/value/value.mli +++ b/lib/value/value.mli @@ -9,7 +9,7 @@ type value = Model.target Model.Data.any val none : value (** [none]: the field is empty (or left as is, on update) *) -val single : ('db, 'ocaml, Model.target) Model.Typ.t * 'ocaml -> value +val single : ('db, 'ocaml, Model.target) Model.Types.t * 'ocaml -> value (** [single (typ, data)]: the value for the field, in its code representation ['ocaml] — a single value, or an [int64 Seq.t] for a multivalued reference — together with the type [typ] of the field *) @@ -35,20 +35,22 @@ val id : t -> int64 than [get v id_ref] when the raw [int64] is what is needed (e.g. to run a query on the row) *) -val id_ref : Model.target Model.Typ.monoreference Model.Typ.named -(** The pre-built {!Model.Typ.named} handle of the reserved field ["id"] +val id_ref : Model.target Model.Types.monoreference Model.Types.named +(** The pre-built {!Model.Types.named} handle of the reserved field ["id"] ({!Model.Identifier.id}) — an integer field present in every row, content or list. This is the key to read the primary key of any value. *) -val get : t -> ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named -> 'ocaml +val get : + t -> ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named -> 'ocaml (** Read a field of the value and return its data directly in its code representation ['ocaml] — e.g. [get v id_ref : int64 option] is the primary key of [v], and a multivalued reference field would yield an [int64 Seq.t]. The match between the requested named type and the readable field is proved - by {!Model.Typ.provably_equal} on name and type. The reserved field [id_ref] - is always readable; the other fields are read from the value's dictionary - (populated by {!load} or {!load'}) and raise [Not_found] when absent. *) + by {!Model.Types.provably_equal} on name and type. The reserved field + [id_ref] is always readable; the other fields are read from the value's + dictionary (populated by {!load} or {!load'}) and raise [Not_found] when + absent. *) val load : Caqti_lwt.connection -> Model.target -> Int64.t -> t Lwt.t (** [load db target id] builds the value for the row [id] of [target] — a -- cgit v1.2.3