(** The data carried by a field of a value. [none] tells the field is empty (or left as is, on update), [v] carries a single value together with the type of its field, and [seq] carries a sequence of references for a multivalued field. The type is parameterized over the type of the data held (['a]: the DB 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 {!Model.Typ.t} stays in the model package; only the data itself lives here. *) type ('a, 't) data = private | None | V : ('a, 't) Model.Typ.t * 'a -> ('a, 't) data | Seq : (int64, 't) Model.Typ.t * int64 Seq.t -> (int64 Seq.t, 't) data (** The constructors are private: a [data] can be pattern-matched from the outside, but it can only be built with [none], [v] and [seq]. *) val none : ('a, 't) data (** [none] tells the field is empty in the database (or left as is, on update) *) val v : ('a, 't) Model.Typ.t * 'a -> ('a, 't) data (** [v (typ, value)] is the value for the field. The field type [typ] is also reported in order to give the compiler the nature of the data, and the result type records the type of the data held *) val seq : (int64, 't) Model.Typ.t * int64 Seq.t -> (int64 Seq.t, 't) data (** [seq (typ, values)] gets a sequence of values for a multivalued field *) (** 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 = private Any : ('a, 't) data -> 't any [@@unboxed] val any : ('a, '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 -> Model.target any = function | "siret" -> any (v (Model.Typ.Text, Some "siret")) | "name" -> any (v (Model.Typ.Text, Some "name")) | _ -> any none ] *)