From fa4970bf1b74f3fa0b2f63cbd461d98c251dc0f0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 20 Nov 2026 18:47:26 +0100 Subject: Updated the model for representing ocaml types in the application type --- lib/value/value.ml | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'lib/value/value.ml') diff --git a/lib/value/value.ml b/lib/value/value.ml index 38c2240..3012667 100644 --- a/lib/value/value.ml +++ b/lib/value/value.ml @@ -1,34 +1,36 @@ -module Fields = Fields - module Data = Data (** The data carried by a field: {!Data.data}, parameterized over the type of - the data held, built with the smart constructors [Data.none], [Data.v], - [Data.seq] *) + the data held, built with the smart constructors [Data.none], [Data.v] *) +type value = Model.target Data.any (** A resolved field data: the data of a field of a content or a list, whatever the type of the data held *) -type value = Model.target Data.any let none : value = Data.any Data.none -let single : ('a, Model.target) Model.Typ.t * 'a -> value = - fun data -> Data.any (Data.v data) - -let multi : (int64, Model.target) Model.Typ.t * int64 Seq.t -> value = - fun data -> Data.any (Data.seq data) +let single : ('db, 'ocaml, Model.target) Model.Typ.t * 'ocaml -> value = + fun data -> Data.any (Data.v data) +type 'a t = { + content : 'a; (** The content or list whose table holds the row *) + id : int64; (** The primary key of the row *) +} (** A value: one row of a content or list table in the database. - The type parameter ['a] is the content or the static list whose table - holds the row: [Model.content] for contents ([Model.content Value.t]) and + The type parameter ['a] is the content or the static list whose table holds + the row: [Model.content] for contents ([Model.content Value.t]) and [Model.list] for lists ([Model.list Value.t]). *) -type 'a t = { - content : 'a; - (** The content or list whose table holds the row *) - id : int64; - (** The primary key of the row *) -} let v : 'a -> int64 -> 'a t = fun content id -> { content; id } let content : 'a t -> 'a = fun t -> t.content let id : 'a t -> int64 = fun t -> t.id + +let id_ref : (Model.target Model.Typ.monoreference) Model.Typ.named = + Model.Typ.named ~name:Model.Identifier.id ~typ:Model.Typ.Integer + +let get : type ocaml. + 'a t -> (('db, ocaml, Model.target) Model.Typ.t) Model.Typ.named -> ocaml = + fun t ref -> + match Model.Typ.provably_equal id_ref ref with + | Some Type.Equal -> Some t.id + | None -> raise Not_found -- cgit v1.2.3