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/configuration/ast.ml | 4 +- lib/model/content.ml | 5 ++- lib/model/data.ml | 6 +-- lib/model/data.mli | 10 ++--- lib/model/field.ml | 18 +++++---- lib/model/field.mli | 10 +++-- lib/model/identifier.ml | 1 + lib/model/model.ml | 6 +-- lib/model/model.mli | 26 ++++++------ lib/model/path.ml | 6 +-- lib/model/typ.ml | 102 ----------------------------------------------- lib/model/typ.mli | 92 ------------------------------------------ lib/model/types.ml | 102 +++++++++++++++++++++++++++++++++++++++++++++++ lib/model/types.mli | 92 ++++++++++++++++++++++++++++++++++++++++++ lib/query/create.ml | 14 +++---- lib/query/encoder.ml | 14 +++---- lib/query/insert.ml | 10 ++--- lib/query/intf.ml | 19 +++++++-- lib/query/select.ml | 24 +++++------ lib/query/select.mli | 2 +- lib/query/update.ml | 14 +++---- lib/value/value.ml | 39 +++++++++--------- lib/value/value.mli | 16 ++++---- 23 files changed, 328 insertions(+), 304 deletions(-) delete mode 100644 lib/model/typ.ml delete mode 100644 lib/model/typ.mli create mode 100644 lib/model/types.ml create mode 100644 lib/model/types.mli (limited to 'lib') diff --git a/lib/configuration/ast.ml b/lib/configuration/ast.ml index 8ea92b2..6703386 100644 --- a/lib/configuration/ast.ml +++ b/lib/configuration/ast.ml @@ -67,7 +67,7 @@ let get_reference_target : Model.field -> Model.content option = | MonoReference r | MultiReference r -> ( (* References to static lists are leaves of the dependency graph: they are not followed here. *) - match r.Model.Typ.t with + match r.Model.Types.t with | Model.Reference.List _ -> None | Model.Reference.Content ref -> ( try Some (Model.Reference.get ref) @@ -127,7 +127,7 @@ let check_fields : Model.Identifier.t -> Model.field Seq.t -> unit = | Some first -> let (T t1) = Model.Field.type_ first in let (T t2) = Model.Field.type_ field in - if Option.is_none (Model.Typ.eq t1 t2) then + if Option.is_none (Model.Types.eq t1 t2) then raise (ConflictingFields (owner, name))) fields diff --git a/lib/model/content.ml b/lib/model/content.ml index 7b9d9a4..a5e5c10 100644 --- a/lib/model/content.ml +++ b/lib/model/content.ml @@ -32,7 +32,8 @@ let fields : 'a t -> 'a Field.t Seq.t = let find_target : 'a t -> string -> 'a option = fun t name -> let feature_opt = - Seq.find (fun f -> String.equal (Identifier.to_string (Field.name f)) name) + Seq.find + (fun f -> String.equal (Identifier.to_string (Field.name f)) name) (fields t) in @@ -40,5 +41,5 @@ let find_target : 'a t -> string -> 'a option = let* feature : 'a Field.t = feature_opt in let (T feature_type) = Field.type_ feature in match feature_type with - | MonoReference t | MultiReference t -> Some t.Typ.t + | MonoReference t | MultiReference t -> Some t.Types.t | Integer | Text -> None diff --git a/lib/model/data.ml b/lib/model/data.ml index 9c44203..2d00c4e 100644 --- a/lib/model/data.ml +++ b/lib/model/data.ml @@ -8,15 +8,15 @@ representation of the field, e.g. [string option] or [int64 option]) and over ['t], the target of the field for references — a reference is held as an [int64] (the id of the target row), while ['t] records what it points to. - The field type {!Typ.t} stays in the model package; only the data itself + The field type {!Types.t} stays in the model package; only the data itself lives here. *) type ('ocaml, 't) data = | None - | V : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data + | V : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data let none : ('ocaml, 't) data = None -let v : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data = +let v : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data = fun (typ, value) -> V (typ, value) type 't any = Any : ('ocaml, 't) data -> 't any [@@unboxed] diff --git a/lib/model/data.mli b/lib/model/data.mli index 6773589..37e7267 100644 --- a/lib/model/data.mli +++ b/lib/model/data.mli @@ -8,18 +8,18 @@ data held (e.g. [string option], [int64 option], or [int64 Seq.t] for a multivalued reference), and over ['t], the target of the field for references. The DB representation ['db] appears only inside the field type - carried by the constructors. The field type {!Typ.t} stays in the model + carried by the constructors. The field type {!Types.t} stays in the model package; only the data itself lives here. *) type ('ocaml, 't) data = private | None - | V : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data + | V : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data val none : ('ocaml, 't) data (** [none] tells the field is empty in the database (or left as is, on update) *) -val v : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data +val v : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data (** [v (typ, value)] is the value for the field, in its code representation ['ocaml] — e.g. a single [string option], or an [int64 Seq.t] for a multivalued reference. The field type [typ] is also reported: it ties the @@ -39,7 +39,7 @@ val any : ('ocaml, 't) data -> 't any (* Function providing the data of each field to insert in the database *) let f : string -> Reference.target any = function - | "siret" -> any (v (Typ.Text, Some "siret")) - | "name" -> any (v (Typ.Text, Some "name")) + | "siret" -> any (v (Types.Text, Some "siret")) + | "name" -> any (v (Types.Text, Some "name")) | _ -> any none ] *) diff --git a/lib/model/field.ml b/lib/model/field.ml index feb712d..241a9df 100644 --- a/lib/model/field.ml +++ b/lib/model/field.ml @@ -2,11 +2,11 @@ type textI18n = (string * string) list (** A label is just an association list*) type validation = { rule : string list Dsl.t; message : textI18n } -type 't field_ex = T : ('db, 'ocaml, 't) Typ.t -> 't field_ex +type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex type 't t = | F : { - named : ('db, 'ocaml, 't) Typ.t Typ.named; + named : ('db, 'ocaml, 't) Types.t Types.named; (** Name and type of the field, tied together *) label : textI18n; placeholder : textI18n option; @@ -21,11 +21,11 @@ type 't t = ['a] — this is what lets {!named_of} re-stamp it with a known type. The type stays abstract in the interface. *) -let name : 'ref t -> Identifier.t = fun (F f) -> Typ.name f.named +let name : 'ref t -> Identifier.t = fun (F f) -> Types.name f.named let label : 'ref t -> textI18n = fun (F f) -> f.label let placeholder : 'ref t -> textI18n option = fun (F f) -> f.placeholder let icon : 'ref t -> unit option = fun (F f) -> f.icon -let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T (Typ.typ f.named) +let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T (Types.typ f.named) let required : 'ref t -> bool = fun (F f) -> f.required let validation : 'ref t -> validation list = fun (F f) -> f.validation let criteria : 'ref t -> string list Dsl.t option = fun (F f) -> f.criteria @@ -44,7 +44,7 @@ let create : ?criteria name -> F { - named = Typ.named ~name ~typ; + named = Types.named ~name ~typ; label; placeholder; icon; @@ -54,11 +54,13 @@ let create : } let named_of : type db ocaml ref. - ref t -> (db, ocaml, ref) Typ.t -> ((db, ocaml, ref) Typ.t) Typ.named option = + ref t -> + (db, ocaml, ref) Types.t -> + (db, ocaml, ref) Types.t Types.named option = fun (F f) typ -> - match Typ.eq typ f.named.typ with + match Types.eq typ f.named.typ with | None -> None | Some Type.Equal -> ( - match Typ.eq_ocaml typ f.named.typ with + match Types.eq_ocaml typ f.named.typ with | None -> None | Some Type.Equal -> Some f.named) diff --git a/lib/model/field.mli b/lib/model/field.mli index 0619f33..3a19ab8 100644 --- a/lib/model/field.mli +++ b/lib/model/field.mli @@ -2,16 +2,18 @@ type textI18n = (string * string) list (** A label is just an association list*) type validation = { rule : string list Dsl.t; message : textI18n } -type 't field_ex = T : ('db, 'ocaml, 't) Typ.t -> 't field_ex +type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex type 'ref t (** Description of a field *) val named_of : - 'ref t -> ('db, 'ocaml, 'ref) Typ.t -> (('db, 'ocaml, 'ref) Typ.t) Typ.named option -(** [named_of field typ] is [Some named] — the field's {!Typ.named} type, + 'ref t -> + ('db, 'ocaml, 'ref) Types.t -> + ('db, 'ocaml, 'ref) Types.t Types.named option +(** [named_of field typ] is [Some named] — the field's {!Types.named} type, stamped with ['db] and ['ocaml] — when [typ] matches the declared type of - [field] (checked with {!Typ.eq} and {!Typ.eq_ocaml}); [None] on type + [field] (checked with {!Types.eq} and {!Types.eq_ocaml}); [None] on type mismatch *) val create : diff --git a/lib/model/identifier.ml b/lib/model/identifier.ml index f1a981e..d7d1f3c 100644 --- a/lib/model/identifier.ml +++ b/lib/model/identifier.ml @@ -25,6 +25,7 @@ let to_string : t -> string = fun id -> id (** The fixed columns of the generated schema, predefined so that the SQL generation can refer to them directly. *) let id : t = of_string "id" + let parent : t = of_string "parent" let target : t = of_string "target" let quote : t -> string = fun id -> "\"" ^ id ^ "\"" diff --git a/lib/model/model.ml b/lib/model/model.ml index c3e5b5b..81d8883 100644 --- a/lib/model/model.ml +++ b/lib/model/model.ml @@ -4,7 +4,7 @@ module Identifier = Identifier module Dsl = Dsl -module Typ = Typ +module Types = Types module Data = Data module Reference = Reference module DataList = Data_list @@ -22,5 +22,5 @@ type content = target Content.t type section = target Section.t type field = target Field.t type field_ex = target Field.field_ex -type reference = target Typ.reference -type ('db, 'ocaml) typ = ('db, 'ocaml, target) Typ.t +type reference = target Types.reference +type ('db, 'ocaml) typ = ('db, 'ocaml, target) Types.t diff --git a/lib/model/model.mli b/lib/model/model.mli index 0326eb2..29d6234 100644 --- a/lib/model/model.mli +++ b/lib/model/model.mli @@ -39,8 +39,8 @@ - {!Identifier} — the names of contents and fields, validated so that they are always safe to embed as SQL identifiers. - {!Content}, {!Section}, {!Field} — the structure of the model. - - {!Typ} — the field types (the nature of the data; the data itself lives in - the value package as [Value.value]). + - {!Types} — the field types (the nature of the data; the data itself lives + in the value package as [Value.value]). - {!Reference} — a link from a reference field to its target content. - {!DataList} — a static list declared in the configuration: referenceable, but not editable by the user. @@ -85,25 +85,25 @@ type content = target Content.t (** A content : the element produced by the configuration loader and manipulated by the query and rendering layers. *) -module Typ = Typ +module Types = Types (** The type of a field, and the values a field can carry. A field type is one of: - - {!Typ.Text} — a string, stored as a nullable column; - - {!Typ.Integer} — an integer, stored as a nullable column; - - {!Typ.MonoReference} — a reference to a single target ({!target}), stored - as a nullable foreign key for a content, or as a plain column for a static - list; - - {!Typ.MultiReference} — a reference to several targets of the same kind, + - {!Types.Text} — a string, stored as a nullable column; + - {!Types.Integer} — an integer, stored as a nullable column; + - {!Types.MonoReference} — a reference to a single target ({!target}), + stored as a nullable foreign key for a content, or as a plain column for a + static list; + - {!Types.MultiReference} — a reference to several targets of the same kind, stored in a dedicated table ["content.field"]. - A {!Typ.reference} record carries the target of a reference field (a + A {!Types.reference} record carries the target of a reference field (a {!target}) plus optional [constraints] restricting the allowed values. The data provided for a field when inserting/updating is a [Value.value] (from the value package): [None] (leave as is), [V] (a single value) or [Seq] (a sequence of references, for multivalued fields). *) -type ('db, 'ocaml) typ = ('db, 'ocaml, target) Typ.t +type ('db, 'ocaml) typ = ('db, 'ocaml, target) Types.t (** A field type descriptor ; ['db] is the database representation of the field (e.g. [string option] for a text field, [int64] for a multivalued reference) *) @@ -116,7 +116,7 @@ module Reference = Reference necessarily exists, and resolved once all contents are registered. This is what allows contents to reference each other, including cyclically. *) -type reference = target Typ.reference +type reference = target Types.reference (** A reference field target: a {!target}, plus optional constraints *) module Data = Data @@ -147,7 +147,7 @@ module Field = Field (** A field of a content. A field has a {!Identifier.t} name, a [label] as a list of - [(language, text)] pairs, a {!Typ.field_ex} type, a [required] flag, and + [(language, text)] pairs, a {!Types.field_ex} type, a [required] flag, and optionally a [placeholder], [validation] rules (a {!Dsl} expression plus a per-language error message) and a [criteria] controlling when the field is displayed. Build one with {!Field.create}. *) diff --git a/lib/model/path.ml b/lib/model/path.ml index dd62864..374b23b 100644 --- a/lib/model/path.ml +++ b/lib/model/path.ml @@ -23,9 +23,9 @@ let target_of_field : Reference.target Field.t -> Reference.target option = fun field -> let (Field.T ty) = Field.type_ field in match ty with - | Typ.MonoReference reference | Typ.MultiReference reference -> - Some reference.Typ.t - | Typ.Text | Typ.Integer -> None + | Types.MonoReference reference | Types.MultiReference reference -> + Some reference.Types.t + | Types.Text | Types.Integer -> None (** Resolve a path from a target. diff --git a/lib/model/typ.ml b/lib/model/typ.ml deleted file mode 100644 index a13653e..0000000 --- a/lib/model/typ.ml +++ /dev/null @@ -1,102 +0,0 @@ -type 'a reference = { - t : 'a; - (** The target of the reference: at the resolved level a - {!Reference.target} (aliased as {!Model.target}). *) - constraints : string list Dsl.t option; - (** Optionally restrict the values allowed for this field, as a DSL - expression read from the optional [["constraints"]] key of the - configuration. Currently carried through to the consumers (e.g. to - filter the proposed values); [None] means no restriction. *) -} -(** A reference from a field to a target (a content or a static list). - - The type stays parameterized over ['a] only to break the module dependency - cycle ([Reference] depends on [Content], which depends on [Field]/[Typ]); in - practice ['a] is always {!Model.target}. Use the aliases [Model.reference], - [Model.content], [Model.field], ... at the use sites. *) - -(** Each of the field types available in the application. - - - ['db] is the representation of the data in the database (the column type). - - ['ocaml] is the representation of the data in the code — usually the same - as ['db], except for multivalued references, stored as one row per value - in a dedicated table (['db = int64]) but manipulated as a sequence in code - (['ocaml = int64 Seq.t]). - - ['t] is the type of the target in references fields *) -type ('db, 'ocaml, 't) t = - | Text : (string option, string option, 't) t - | Integer : (int64 option, int64 option, 't) t - | MonoReference : 't reference -> (int64 option, int64 option, 't) t - | MultiReference : 't reference -> (int64, int64 Seq.t, 't) t - (** Multireferences properties allows only one kind of content. - - They are not encoded in the content table but in another table *) - -type 'target monoreference = (int64 option, int64 option, 'target) t -(** The type of a reference field: the [int64] id of the target row in the - database, an [int64 option] in code. In practice ['target] is always - {!Model.target}. *) - -type 'target multireference = (int64, int64 Seq.t, 'target) t -(** The type of a multivalued reference field: one [int64] per row in the - dedicated table (['db]), an [int64 Seq.t] in code (['ocaml]). In practice - ['target] is always {!Model.target}. *) - -(** Get the value to insert in the database when the field is empty *) -let default_value : type a b c. (a, b, c) t -> a = function - | Integer -> None - | Text -> None - | MonoReference _ -> None - | MultiReference _ -> raise Not_found - -(** Constructor-level equality on the ['db] representation *) -let eq : type a b x y c. (a, x, c) t -> (b, y, c) t -> (a, b) Type.eq option = - fun t1 t2 -> - match (t1, t2) with - | MultiReference _, MultiReference _ -> Some Type.Equal - | MonoReference _, MonoReference _ -> Some Type.Equal - | Integer, Integer -> Some Type.Equal - | Text, Text -> Some Type.Equal - | _ -> None - -(** Constructor-level equality on the ['ocaml] representation *) -let eq_ocaml : type a b x y c. - (a, x, c) t -> (b, y, c) t -> (x, y) Type.eq option = - fun t1 t2 -> - match (t1, t2) with - | MultiReference _, MultiReference _ -> Some Type.Equal - | MonoReference _, MonoReference _ -> Some Type.Equal - | Integer, Integer -> Some Type.Equal - | Text, Text -> Some Type.Equal - | _ -> None - -type 'typ named = { - name : Identifier.t; (** The internal name of the field *) - typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) -} -(** A named field type: a {!t} together with the field's name. - - Named types are built on the fly with {!named} (e.g. from a field, see - {!Field.named_of}) and used locally as typed handles — e.g. to read the data - of a field from a value. A pre-built instance exists for the reserved field - [["id"]] (see [Value.id_ref]). *) - -(** Build a named type from a name and a type — no uniqueness involved, so - values built on the fly denote the same field *) -let named : name:Identifier.t -> typ:'typ -> 'typ named = - fun ~name ~typ -> { name; typ } - -let name : 'typ named -> Identifier.t = fun n -> n.name -let typ : 'typ named -> 'typ = fun n -> n.typ - -(** [provably_equal n1 n2] is [Some Equal] iff [n1] and [n2] denote the same - field — same name — and their types match, which also proves that their - ['ocaml] representations are equal *) -let provably_equal (type a b x y c) (n1 : (a, x, c) t named) - (n2 : (b, y, c) t named) : (x, y) Type.eq option = - if Identifier.equal n1.name n2.name then eq_ocaml n1.typ n2.typ else None - -(** [same n1 n2] is [true] iff [n1] and [n2] denote the same field with matching - types *) -let same : ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> bool = - fun n1 n2 -> provably_equal n1 n2 <> None diff --git a/lib/model/typ.mli b/lib/model/typ.mli deleted file mode 100644 index 42350a3..0000000 --- a/lib/model/typ.mli +++ /dev/null @@ -1,92 +0,0 @@ -(** The field types of the application model. - - A field type describes the nature of the data a field can carry, at two - levels: - - - ['db] is the representation in the database (the column type); - - ['ocaml] is the representation in the code — usually equal to ['db], - except for multivalued references, stored as one row per value in a - dedicated table (['db = int64]) but manipulated as a sequence in code - (['ocaml = int64 Seq.t]). - - The third parameter ['t] is the target of the field when it is a - reference (a content or a static list, i.e. {!Model.target}). *) - -type 'a reference = { - t : 'a; - (** The target of the reference: at the resolved level a - {!Reference.target} (aliased as {!Model.target}). *) - constraints : string list Dsl.t option; - (** Optionally restrict the values allowed for this field, as a DSL - expression read from the optional ["constraints"] key of the - configuration. Currently carried through to the consumers (e.g. to - filter the proposed values); [None] means no restriction. *) -} -(** A reference from a field to a target (a content or a static list). - - The type stays parameterized over ['a] only to break the module dependency - cycle ([Reference] depends on [Content], which depends on [Field]/[Typ]); - in practice ['a] is always {!Model.target}. *) - -type ('db, 'ocaml, 't) t = - | Text : (string option, string option, 't) t - | Integer : (int64 option, int64 option, 't) t - | MonoReference : 't reference -> (int64 option, int64 option, 't) t - | MultiReference : 't reference -> (int64, int64 Seq.t, 't) t - (** Multireference fields allow only one kind of target. - - They are not encoded in the content table but in another table *) - -type 'target monoreference = (int64 option, int64 option, 'target) t -(** The type of a reference field: the [int64] id of the target row in the - database, an [int64 option] in code. In practice ['target] is always - {!Model.target}. *) - -type 'target multireference = (int64, int64 Seq.t, 'target) t -(** The type of a multivalued reference field: one [int64] per row in the - dedicated table (['db]), an [int64 Seq.t] in code (['ocaml]). In practice - ['target] is always {!Model.target}. *) - -val default_value : ('a, 'b, 'c) t -> 'a -(** The value to insert in the database when the field is empty *) - -val eq : ('a, 'x, 'c) t -> ('b, 'y, 'c) t -> ('a, 'b) Type.eq option -(** Constructor-level equality on the ['db] representation: [eq t1 t2] is - [Some Equal] when [t1] and [t2] have the same constructor, which also proves - ['a = 'b] *) - -val eq_ocaml : ('a, 'x, 'c) t -> ('b, 'y, 'c) t -> ('x, 'y) Type.eq option -(** Constructor-level equality on the ['ocaml] representation: [eq_ocaml t1 t2] - is [Some Equal] when [t1] and [t2] have the same constructor, which also - proves ['x = 'y] *) - -type 'typ named = { - name : Identifier.t; (** The internal name of the field *) - typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) -} -(** A named field type: a {!t} together with the field's name. - - Named types are built on the fly with {!named} (e.g. from a field, see - {!Field.named_of}) and used locally as typed handles — e.g. to read the - data of a field from a value. A pre-built instance exists for the reserved - field ["id"] (see [Value.id_ref]). *) - -val named : name:Identifier.t -> typ:'typ -> 'typ named -(** Build a named type from a name and a type — no uniqueness involved, so - values built on the fly denote the same field *) - -val name : 'typ named -> Identifier.t -(** The name of the field *) - -val typ : 'typ named -> 'typ -(** The type of the named field *) - -val provably_equal : - ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> ('x, 'y) Type.eq option -(** [provably_equal n1 n2] is [Some Equal] iff [n1] and [n2] denote the same - field — same name — and their types match, which also proves that their - ['ocaml] representations are equal *) - -val same : ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> bool -(** [same n1 n2] is [true] iff [n1] and [n2] denote the same field with matching - types *) diff --git a/lib/model/types.ml b/lib/model/types.ml new file mode 100644 index 0000000..ee244d3 --- /dev/null +++ b/lib/model/types.ml @@ -0,0 +1,102 @@ +type 'a reference = { + t : 'a; + (** The target of the reference: at the resolved level a + {!Reference.target} (aliased as {!Model.target}). *) + constraints : string list Dsl.t option; + (** Optionally restrict the values allowed for this field, as a DSL + expression read from the optional [["constraints"]] key of the + configuration. Currently carried through to the consumers (e.g. to + filter the proposed values); [None] means no restriction. *) +} +(** A reference from a field to a target (a content or a static list). + + The type stays parameterized over ['a] only to break the module dependency + cycle ([Reference] depends on [Content], which depends on [Field]/[Types]); + in practice ['a] is always {!Model.target}. Use the aliases + [Model.reference], [Model.content], [Model.field], ... at the use sites. *) + +(** Each of the field types available in the application. + + - ['db] is the representation of the data in the database (the column type). + - ['ocaml] is the representation of the data in the code — usually the same + as ['db], except for multivalued references, stored as one row per value + in a dedicated table (['db = int64]) but manipulated as a sequence in code + (['ocaml = int64 Seq.t]). + - ['t] is the type of the target in references fields *) +type ('db, 'ocaml, 't) t = + | Text : (string option, string option, 't) t + | Integer : (int64 option, int64 option, 't) t + | MonoReference : 't reference -> (int64 option, int64 option, 't) t + | MultiReference : 't reference -> (int64, int64 Seq.t, 't) t + (** Multireferences properties allows only one kind of content. + + They are not encoded in the content table but in another table *) + +type 'target monoreference = (int64 option, int64 option, 'target) t +(** The type of a reference field: the [int64] id of the target row in the + database, an [int64 option] in code. In practice ['target] is always + {!Model.target}. *) + +type 'target multireference = (int64, int64 Seq.t, 'target) t +(** The type of a multivalued reference field: one [int64] per row in the + dedicated table (['db]), an [int64 Seq.t] in code (['ocaml]). In practice + ['target] is always {!Model.target}. *) + +(** Get the value to insert in the database when the field is empty *) +let default_value : type a b c. (a, b, c) t -> a = function + | Integer -> None + | Text -> None + | MonoReference _ -> None + | MultiReference _ -> raise Not_found + +(** Constructor-level equality on the ['db] representation *) +let eq : type a b x y c. (a, x, c) t -> (b, y, c) t -> (a, b) Type.eq option = + fun t1 t2 -> + match (t1, t2) with + | MultiReference _, MultiReference _ -> Some Type.Equal + | MonoReference _, MonoReference _ -> Some Type.Equal + | Integer, Integer -> Some Type.Equal + | Text, Text -> Some Type.Equal + | _ -> None + +(** Constructor-level equality on the ['ocaml] representation *) +let eq_ocaml : type a b x y c. + (a, x, c) t -> (b, y, c) t -> (x, y) Type.eq option = + fun t1 t2 -> + match (t1, t2) with + | MultiReference _, MultiReference _ -> Some Type.Equal + | MonoReference _, MonoReference _ -> Some Type.Equal + | Integer, Integer -> Some Type.Equal + | Text, Text -> Some Type.Equal + | _ -> None + +type 'typ named = { + name : Identifier.t; (** The internal name of the field *) + typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) +} +(** A named field type: a {!t} together with the field's name. + + Named types are built on the fly with {!named} (e.g. from a field, see + {!Field.named_of}) and used locally as typed handles — e.g. to read the data + of a field from a value. A pre-built instance exists for the reserved field + [["id"]] (see [Value.id_ref]). *) + +(** Build a named type from a name and a type — no uniqueness involved, so + values built on the fly denote the same field *) +let named : name:Identifier.t -> typ:'typ -> 'typ named = + fun ~name ~typ -> { name; typ } + +let name : 'typ named -> Identifier.t = fun n -> n.name +let typ : 'typ named -> 'typ = fun n -> n.typ + +(** [provably_equal n1 n2] is [Some Equal] iff [n1] and [n2] denote the same + field — same name — and their types match, which also proves that their + ['ocaml] representations are equal *) +let provably_equal (type a b x y c) (n1 : (a, x, c) t named) + (n2 : (b, y, c) t named) : (x, y) Type.eq option = + if Identifier.equal n1.name n2.name then eq_ocaml n1.typ n2.typ else None + +(** [same n1 n2] is [true] iff [n1] and [n2] denote the same field with matching + types *) +let same : ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> bool = + fun n1 n2 -> provably_equal n1 n2 <> None diff --git a/lib/model/types.mli b/lib/model/types.mli new file mode 100644 index 0000000..81c9d5b --- /dev/null +++ b/lib/model/types.mli @@ -0,0 +1,92 @@ +(** The field types of the application model. + + A field type describes the nature of the data a field can carry, at two + levels: + + - ['db] is the representation in the database (the column type); + - ['ocaml] is the representation in the code — usually equal to ['db], + except for multivalued references, stored as one row per value in a + dedicated table (['db = int64]) but manipulated as a sequence in code + (['ocaml = int64 Seq.t]). + + The third parameter ['t] is the target of the field when it is a reference + (a content or a static list, i.e. {!Model.target}). *) + +type 'a reference = { + t : 'a; + (** The target of the reference: at the resolved level a + {!Reference.target} (aliased as {!Model.target}). *) + constraints : string list Dsl.t option; + (** Optionally restrict the values allowed for this field, as a DSL + expression read from the optional ["constraints"] key of the + configuration. Currently carried through to the consumers (e.g. to + filter the proposed values); [None] means no restriction. *) +} +(** A reference from a field to a target (a content or a static list). + + The type stays parameterized over ['a] only to break the module dependency + cycle ([Reference] depends on [Content], which depends on [Field]/[Types]); + in practice ['a] is always {!Model.target}. *) + +type ('db, 'ocaml, 't) t = + | Text : (string option, string option, 't) t + | Integer : (int64 option, int64 option, 't) t + | MonoReference : 't reference -> (int64 option, int64 option, 't) t + | MultiReference : 't reference -> (int64, int64 Seq.t, 't) t + (** Multireference fields allow only one kind of target. + + They are not encoded in the content table but in another table *) + +type 'target monoreference = (int64 option, int64 option, 'target) t +(** The type of a reference field: the [int64] id of the target row in the + database, an [int64 option] in code. In practice ['target] is always + {!Model.target}. *) + +type 'target multireference = (int64, int64 Seq.t, 'target) t +(** The type of a multivalued reference field: one [int64] per row in the + dedicated table (['db]), an [int64 Seq.t] in code (['ocaml]). In practice + ['target] is always {!Model.target}. *) + +val default_value : ('a, 'b, 'c) t -> 'a +(** The value to insert in the database when the field is empty *) + +val eq : ('a, 'x, 'c) t -> ('b, 'y, 'c) t -> ('a, 'b) Type.eq option +(** Constructor-level equality on the ['db] representation: [eq t1 t2] is + [Some Equal] when [t1] and [t2] have the same constructor, which also proves + ['a = 'b] *) + +val eq_ocaml : ('a, 'x, 'c) t -> ('b, 'y, 'c) t -> ('x, 'y) Type.eq option +(** Constructor-level equality on the ['ocaml] representation: [eq_ocaml t1 t2] + is [Some Equal] when [t1] and [t2] have the same constructor, which also + proves ['x = 'y] *) + +type 'typ named = { + name : Identifier.t; (** The internal name of the field *) + typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) +} +(** A named field type: a {!t} together with the field's name. + + Named types are built on the fly with {!named} (e.g. from a field, see + {!Field.named_of}) and used locally as typed handles — e.g. to read the data + of a field from a value. A pre-built instance exists for the reserved field + ["id"] (see [Value.id_ref]). *) + +val named : name:Identifier.t -> typ:'typ -> 'typ named +(** Build a named type from a name and a type — no uniqueness involved, so + values built on the fly denote the same field *) + +val name : 'typ named -> Identifier.t +(** The name of the field *) + +val typ : 'typ named -> 'typ +(** The type of the named field *) + +val provably_equal : + ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> ('x, 'y) Type.eq option +(** [provably_equal n1 n2] is [Some Equal] iff [n1] and [n2] denote the same + field — same name — and their types match, which also proves that their + ['ocaml] representations are equal *) + +val same : ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> bool +(** [same n1 n2] is [true] iff [n1] and [n2] denote the same field with matching + types *) diff --git a/lib/query/create.ml b/lib/query/create.ml index 49047a7..cf364cf 100644 --- a/lib/query/create.ml +++ b/lib/query/create.ml @@ -39,8 +39,7 @@ ADD FOREIGN KEY (best_a_id) REFERENCES answer(a_id); *) -let get_foreign_statement : - Model.Identifier.t -> Model.Identifier.t -> string = +let get_foreign_statement : Model.Identifier.t -> Model.Identifier.t -> string = fun property dst_table -> "FOREIGN KEY(" ^ Model.Identifier.quote property @@ -69,7 +68,7 @@ let create_external_reference_table : (* The target is the id of a row in the target content table, or in the dedicated table of the target list *) let target_table = - match reference.Model.Typ.t with + match reference.Model.Types.t with | Model.Reference.Content ref -> Model.Content.id (Model.Reference.get ref) | Model.Reference.List list -> list.Model.DataList.id @@ -129,7 +128,7 @@ let create_list_table : match Model.Field.type_ field with | T (MonoReference reference) -> ( let column = Model.Field.name field in - match reference.Model.Typ.t with + match reference.Model.Types.t with | Model.Reference.List target -> let dst = target.Model.DataList.id in if List.mem ~set:created dst then @@ -149,7 +148,7 @@ let create_list_table : let fields = "\"id\" INTEGER PRIMARY KEY" :: List.fold_left list_fields ~init:foreign ~f:(fun acc field -> - match get_field_query field with None -> acc | Some q -> q :: acc) + match get_field_query field with None -> acc | Some q -> q :: acc) in let buff = Buffer.create 128 in let format = Format.formatter_of_buffer buff in @@ -217,7 +216,7 @@ let rec create_table : match Model.Field.type_ field with | T (MonoReference reference) -> ( let column = Model.Field.name field in - match reference.Model.Typ.t with + match reference.Model.Types.t with | Model.Reference.List list -> (* The list tables are created before the content tables, so the constraint can be declared directly *) @@ -335,7 +334,8 @@ let create : Caqti_lwt.connection -> Configuration.Ast.setting -> unit Lwt.t = let* foreign, _ = Lwt_list.fold_left_s (fun acc list -> create_list_table db acc list) - ([], []) (Configuration.Ast.lists conf) + ([], []) + (Configuration.Ast.lists conf) in let contents = Configuration.Ast.root_contents conf in let* foreign, _ = diff --git a/lib/query/encoder.ml b/lib/query/encoder.ml index 5e5f402..4c8d528 100644 --- a/lib/query/encoder.ml +++ b/lib/query/encoder.ml @@ -304,18 +304,18 @@ module DataToCaqtiValues = Map (struct | Model.Data.None -> (* The provider does not have any value for this property, use the default value*) - Model.Typ.default_value content_type + Model.Types.default_value content_type | Model.Data.V (field_type', value) -> ( (* For the single-column fields handled here, the DB and code representations coincide — match the field type to prove it *) - let check (type x) (ct : (x, x, Model.target) Model.Typ.t) : x = - match Model.Typ.eq_ocaml ct field_type' with + let check (type x) (ct : (x, x, Model.target) Model.Types.t) : x = + match Model.Types.eq_ocaml ct field_type' with | Some Equal -> value | None -> raise TypeMismatch in match content_type with - | Model.Typ.MultiReference _ -> raise TypeMismatch - | Model.Typ.Text as ct -> check ct - | Model.Typ.Integer as ct -> check ct - | Model.Typ.MonoReference _ as ct -> check ct)) + | Model.Types.MultiReference _ -> raise TypeMismatch + | Model.Types.Text as ct -> check ct + | Model.Types.Integer as ct -> check ct + | Model.Types.MonoReference _ as ct -> check ct)) end) diff --git a/lib/query/insert.ml b/lib/query/insert.ml index 26597d8..98a5c88 100644 --- a/lib/query/insert.ml +++ b/lib/query/insert.ml @@ -63,12 +63,12 @@ module MultiReferencesInsert = struct let parent = Identifier.quote Identifier.parent and target = Identifier.quote Identifier.target in match content_type with - | Model.Typ.MultiReference _target -> ( + | Model.Types.MultiReference _target -> ( let (Model.Data.Any d) = provider (Model.Identifier.to_string name) in match d with | Model.Data.None -> acc | Model.Data.V (field_type', values) -> ( - match Model.Typ.eq_ocaml content_type field_type' with + match Model.Types.eq_ocaml content_type field_type' with | None -> raise Encoder.TypeMismatch | Some Equal -> let q = @@ -116,7 +116,7 @@ let insert_row : collect_fields ~init_fields ~filter:(fun field -> let (T ty) = Model.Field.type_ field in - match ty with Model.Typ.MultiReference _ -> false | _ -> true) + match ty with Model.Types.MultiReference _ -> false | _ -> true) fields in let insert_template = @@ -150,7 +150,7 @@ let insert_row : let (T multi_valuated_fields) = collect_fields fields ~filter:(fun field -> let (T ty) = Model.Field.type_ field in - match ty with Model.Typ.MultiReference _ -> true | _ -> false) + match ty with Model.Types.MultiReference _ -> true | _ -> false) in let acc = @@ -202,7 +202,7 @@ let insert : (* Otherwise update the provider to give a value for the parent *) function | "parent" -> - Model.Data.any (Model.Data.v (Model.Typ.Integer, Some parent_id)) + Model.Data.any (Model.Data.v (Model.Types.Integer, Some parent_id)) | other -> provider other) in let module Db = (val db) in diff --git a/lib/query/intf.ml b/lib/query/intf.ml index d00c17b..e848d3c 100644 --- a/lib/query/intf.ml +++ b/lib/query/intf.ml @@ -15,15 +15,28 @@ type _ tuple = | T1 : ('a, _) data -> 'a tuple | T2 : ('a, _) data * ('b, _) data -> ('a * 'b) tuple | T3 : ('a, _) data * ('b, _) data * ('c, _) data -> ('a * 'b * 'c) tuple - | T4 : ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data -> ('a * 'b * 'c * 'd) tuple + | T4 : + ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data + -> ('a * 'b * 'c * 'd) tuple | T5 : ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data * ('e, _) data -> ('a * 'b * 'c * 'd * 'e) tuple | T6 : - ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data * ('e, _) data * ('f, _) data + ('a, _) data + * ('b, _) data + * ('c, _) data + * ('d, _) data + * ('e, _) data + * ('f, _) data -> ('a * 'b * 'c * 'd * 'e * 'f) tuple | T7 : - ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data * ('e, _) data * ('f, _) data * ('g, _) data + ('a, _) data + * ('b, _) data + * ('c, _) data + * ('d, _) data + * ('e, _) data + * ('f, _) data + * ('g, _) data -> ('a * 'b * 'c * 'd * 'e * 'f * 'g) tuple | T8 : ('a, _) data diff --git a/lib/query/select.ml b/lib/query/select.ml index ed7fd0b..cdcaeed 100644 --- a/lib/query/select.ml +++ b/lib/query/select.ml @@ -6,7 +6,7 @@ let ( let* ) = Lwt.bind type callback = { f : 'db 'ocaml. - ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named * 'ocaml -> unit; + ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named * 'ocaml -> unit; } (** Call the callback for one single-column field. For those fields the database @@ -15,16 +15,16 @@ type callback = { let apply_field : type a b. callback -> (a, b) Intf.data -> a -> unit = fun k Intf.{ name; content_type } value -> match content_type with - | Model.Typ.Text -> - let named = Model.Typ.named ~name ~typ:content_type in + | Model.Types.Text -> + let named = Model.Types.named ~name ~typ:content_type in k.f (named, value) - | Model.Typ.Integer -> - let named = Model.Typ.named ~name ~typ:content_type in + | Model.Types.Integer -> + let named = Model.Types.named ~name ~typ:content_type in k.f (named, value) - | Model.Typ.MonoReference _ -> - let named = Model.Typ.named ~name ~typ:content_type in + | Model.Types.MonoReference _ -> + let named = Model.Types.named ~name ~typ:content_type in k.f (named, value) - | Model.Typ.MultiReference _ -> raise Encoder.TypeMismatch + | Model.Types.MultiReference _ -> raise Encoder.TypeMismatch (** Call the callback for each field of the tuple, zipping the type descriptors with the row read from the database *) @@ -134,8 +134,8 @@ let select_multireference : let name = Model.Field.name field in let (Model.Field.T content_type) = Model.Field.type_ field in match content_type with - | Model.Typ.MultiReference _ -> - let named = Model.Typ.named ~name ~typ:content_type in + | Model.Types.MultiReference _ -> + let named = Model.Types.named ~name ~typ:content_type in let q = Croquette_common.Format.format_string (fun format -> Format.fprintf format "SELECT %s FROM %s WHERE %s = ?" @@ -167,7 +167,7 @@ let select_row : let init_fields = if has_parent then [ - Model.Field.create (Model.Field.T Model.Typ.Integer) [] ~required:true + Model.Field.create (Model.Field.T Model.Types.Integer) [] ~required:true Model.Identifier.parent; ] else [] @@ -175,7 +175,7 @@ let select_row : let fields = init_fields @ fields in let is_multireference field = match Model.Field.type_ field with - | Model.Field.T (Model.Typ.MultiReference _) -> true + | Model.Field.T (Model.Types.MultiReference _) -> true | _ -> false in let single_fields = List.filter (fun f -> not (is_multireference f)) fields in diff --git a/lib/query/select.mli b/lib/query/select.mli index f93455a..68e4d00 100644 --- a/lib/query/select.mli +++ b/lib/query/select.mli @@ -3,7 +3,7 @@ type callback = { f : 'db 'ocaml. - ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named * 'ocaml -> unit; + ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named * 'ocaml -> unit; } (** A callback called once per field of the selected row, with the field's named type and its data in the code representation ['ocaml] — a pair that can be diff --git a/lib/query/update.ml b/lib/query/update.ml index 08a7551..9bd1f2b 100644 --- a/lib/query/update.ml +++ b/lib/query/update.ml @@ -60,7 +60,7 @@ module ReferenceListEncoder = Encoder.Map (struct include Encoder.DefaultEncoder type 'a t = 'a - type env = Model.target Model.Typ.multireference * Int64.t Seq.t ref + type env = Model.target Model.Types.multireference * Int64.t Seq.t ref let f : type a b. env -> (a, b) Intf.data -> a t = fun (t, env) d -> @@ -68,7 +68,7 @@ module ReferenceListEncoder = Encoder.Map (struct | Seq.Nil -> raise Not_found | Cons (value, tl) -> ( env := tl; - match Model.Typ.eq t d.Intf.content_type with + match Model.Types.eq t d.Intf.content_type with | Some Type.Equal -> value | None -> raise Encoder.TypeMismatch) end) @@ -78,7 +78,7 @@ module ReferencesSet = Set.Make (Int64) let update_mulivaluated_field : Caqti_lwt.connection -> Model.content -> - (Model.Identifier.t * Model.target Model.Typ.multireference * int64 Seq.t) + (Model.Identifier.t * Model.target Model.Types.multireference * int64 Seq.t) list -> int64 -> unit Lwt.t = @@ -169,7 +169,7 @@ let q : (fun ((fields, references) as acc : (Intf.t_type * (string * Model.target Model.Data.any)) list * (Model.Identifier.t - * Model.target Model.Typ.multireference + * Model.target Model.Types.multireference * int64 Seq.t) list) field -> let name = Model.Field.name field in @@ -177,13 +177,13 @@ let q : let tt = Intf.TT { name; content_type } in let (Model.Data.Any d) = provider (Model.Identifier.to_string name) in match content_type with - | Model.Typ.MultiReference _ -> ( + | Model.Types.MultiReference _ -> ( match d with | Model.Data.None -> acc | Model.Data.V (t, seq) -> ( match - ( Model.Typ.eq content_type t, - Model.Typ.eq_ocaml content_type t ) + ( Model.Types.eq content_type t, + Model.Types.eq_ocaml content_type t ) with | Some Type.Equal, Some Type.Equal -> (fields, (name, t, seq) :: references) 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