From ce13c93cf14cb71894481b0303a7058a72a6f4ce Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 21 Nov 2026 11:23:41 +0100 Subject: Load values from the database --- lib/model/data.mli | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/model/data.mli (limited to 'lib/model/data.mli') diff --git a/lib/model/data.mli b/lib/model/data.mli new file mode 100644 index 0000000..6773589 --- /dev/null +++ b/lib/model/data.mli @@ -0,0 +1,45 @@ +(** The data carried by a field of a value. + + [none] tells the field is empty (or left as is, on update), and [v] carries + the value of the field together with its type — a single value, or a + sequence of references for a multivalued field. + + The type is parameterized over ['ocaml], the in-code representation of the + 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 + package; only the data itself lives here. *) + +type ('ocaml, 't) data = private + | None + | V : ('db, 'ocaml, 't) Typ.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 +(** [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 + payload to the field and determines the result type. Whether the value is a + sequence is carried by the type, not by a separate constructor. *) + +(** Existential pack over the held type: the data of a field whose type is not + known statically (e.g. the data of any field of a content, as returned by a + provider function). Matchable from the outside, but built with [any]. *) +type 't any = Any : ('ocaml, 't) data -> 't any [@@unboxed] + +val any : ('ocaml, 't) data -> 't any +(** Pack a typed [data] into an [any], hiding the type of the data held *) + +(** Example for inserting data — build the data of each field, then pack it: + [ + (* 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")) + | _ -> any none + ] *) -- cgit v1.2.3