summaryrefslogtreecommitdiff
path: root/lib/value/value.mli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/value/value.mli')
-rw-r--r--lib/value/value.mli58
1 files changed, 36 insertions, 22 deletions
diff --git a/lib/value/value.mli b/lib/value/value.mli
index eb03965..0d00bf7 100644
--- a/lib/value/value.mli
+++ b/lib/value/value.mli
@@ -14,6 +14,10 @@ val single : ('db, 'ocaml, Model.target) Model.Types.t * 'ocaml -> value
['ocaml] — a single value, or an [int64 Seq.t] for a multivalued reference —
together with the type [typ] of the field *)
+module Property = Property
+(** A property of a value: a field name tied to its {!Model.Types.t} — the typed
+ handle used to read a field of a value with {!get}. *)
+
type t
(** A value: a row of a content or list table in the database, identified by its
{!Model.target} and its [id].
@@ -35,40 +39,50 @@ 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.Types.monoreference Model.Types.named
-(** The pre-built {!Model.Types.named} handle of the reserved field ["id"]
+val id_ref : Model.target Model.Types.monoreference Property.t
+(** The pre-built {!Property.t} 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.Types.t Model.Types.named -> 'ocaml
+val get : t -> ('db, 'ocaml, Model.target) Model.Types.t Property.t -> '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.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
- content (wrap it with {!Model.Reference.of_content}) or a static list — and
- reads the row from the database (one query for the table, plus one per
- multivalued reference field), storing each field in the value's dictionary.
- The returned value is complete: {!get} reads every field as typed data.
+ The match between the requested property and the readable field is proved by
+ {!Property.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 ->
+ ?multivalued:bool ->
+ Model.target ->
+ Int64.t ->
+ t Lwt.t
+(** [load ?multivalued db target id] builds the value for the row [id] of
+ [target] — a content (wrap it with {!Model.Reference.of_content}) or a
+ static list — and reads the row from the database (one query for the table,
+ plus one per multivalued reference field), storing each field in the value's
+ dictionary. The returned value is complete: {!get} reads every field as
+ typed data.
+
+ [~multivalued] (default [true]) tells whether the multivalued reference
+ fields are also loaded: with [~multivalued:false], only the row of the table
+ is read, and the multivalued fields are left out of the dictionary — {!get}
+ raises [Not_found] on them.
The primary key needs no loading — {!get} with {!id_ref} reads it directly
from the value. Use {!v} instead when the fields are already known and no
database read is wanted. *)
-val load' : Caqti_lwt.connection -> t -> unit Lwt.t
-(** [load' db v] reads the row of [v] from the database (one query for the
- table, plus one per multivalued reference field) and stores each field in
- [v]'s dictionary. The value is modified in place — the dictionary is part of
- its state — so the function returns [unit]. Use it to populate a value built
- with {!v}; {!load} is the shortcut that builds and loads in one call. *)
+val load' : Caqti_lwt.connection -> ?multivalued:bool -> t -> unit Lwt.t
+(** [load' ?multivalued db v] reads the row of [v] from the database (one query
+ for the table, plus one per multivalued reference field, unless
+ [~multivalued:false]) and stores each field in [v]'s dictionary. The value
+ is modified in place — the dictionary is part of its state — so the function
+ returns [unit]. Use it to populate a value built with {!v}; {!load} is the
+ shortcut that builds and loads in one call. *)
val pp : Format.formatter -> t -> unit
(** Pretty-print a value as [{ id = …; field = …; … }]: the primary key and the