(** Operations on the values stored in the database (fetching, updating, …). A value is one row of a content or list table in the database. *) type value = Model.target Model.Data.any (** The data of a field of a content or a list, whatever the type of the data held: an existential pack over {!Model.Data.data} *) 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 (** [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 *) type 'a t (** A value: a row of the table of the content or list ['a], identified by its [id]. The 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]). The type is abstract: a value is built with [v] and inspected with [content] and [id]. *) val v : 'a -> int64 -> 'a t (** Build a value from its content or list and its row id *) val content : 'a t -> 'a (** The content or list the value belongs to *) val id : 'a t -> int64 [@@deprecated "Use [Value.get v Value.id_ref] to read the primary key as typed data"] (** The primary key of the value in its table *) val id_ref : Model.target Model.Typ.monoreference Model.Typ.named (** The pre-built {!Model.Typ.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 : 'a t -> ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.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 (see {!add_field}) and raise [Not_found] when absent. *) val load : Caqti_lwt.connection -> Model.content t -> unit Lwt.t (** [load db v] reads the row of [v] in the database (one query for the content table, plus one per multivalued reference field) and stores each field in [v]'s dictionary with {!add_field}, so that {!get} can then read every field as typed data. The value is modified in place — the dictionary is part of its state — so the function returns [unit]. The dictionary is empty when the value is built with {!v}: [load] is what populates it. The primary key needs no loading — {!get} with {!id_ref} reads it directly from the value. *) val pp : Format.formatter -> 'a t -> unit (** Pretty-print a value as [{ id = …; field = …; … }]: the primary key and the fields currently held in the value's dictionary, sorted by field name (the dictionary is a hashtable, sorting keeps the output stable). The content or list the value belongs to is not printed — its type ['a] is abstract here — and neither are the fields not loaded yet: only what {!load} (or {!add_field}) put in the dictionary is shown. *)