summaryrefslogtreecommitdiff
path: root/lib/value/value.mli
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2026-11-21 11:23:41 +0100
committerSébastien Dailly <sebastien@dailly.me>2026-11-21 11:23:41 +0100
commitce13c93cf14cb71894481b0303a7058a72a6f4ce (patch)
treebd93186a65f6645cb4401f188d266d743cc2fde7 /lib/value/value.mli
parent172a02b80d8dbdcfe09129d7fa76015bb5ec4d79 (diff)
Load values from the database
Diffstat (limited to 'lib/value/value.mli')
-rw-r--r--lib/value/value.mli36
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/value/value.mli b/lib/value/value.mli
index 5c493aa..5a8984d 100644
--- a/lib/value/value.mli
+++ b/lib/value/value.mli
@@ -2,15 +2,9 @@
A value is one row of a content or list table in the database. *)
-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]);
- and {!Data.any}, the existential pack used when the held type is not known
- statically *)
-
-type value = Model.target Data.any
+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 {!Data.data} *)
+ held: an existential pack over {!Model.Data.data} *)
val none : value
(** [none]: the field is empty (or left as is, on update) *)
@@ -54,6 +48,26 @@ val get :
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. Only the reserved field
- [id_ref] is readable for now; the other fields are read from the database
- (not implemented yet) and raise [Not_found]. *)
+ 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. *)