summaryrefslogtreecommitdiff
path: root/lib/query/select.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/query/select.mli
parent172a02b80d8dbdcfe09129d7fa76015bb5ec4d79 (diff)
Load values from the database
Diffstat (limited to 'lib/query/select.mli')
-rw-r--r--lib/query/select.mli30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/query/select.mli b/lib/query/select.mli
new file mode 100644
index 0000000..338cef8
--- /dev/null
+++ b/lib/query/select.mli
@@ -0,0 +1,30 @@
+(** Read a row of a content table from the database *)
+
+type callback = {
+ f :
+ 'db 'ocaml.
+ ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named * 'ocaml -> unit;
+}
+(** A callback called once per field of the selected row, with the field's named
+ type and its data in the code representation ['ocaml] — a pair that can be
+ stored in a value's dictionary and read back as typed data.
+
+ The field is existentially typed: ['db] and ['ocaml] are universally
+ quantified in the record field, so a plain function works for a field of any
+ type: [ { f = fun (named, data) -> ... } ]. *)
+
+val select :
+ Caqti_lwt.connection -> Int64.t -> Model.content -> callback -> unit Lwt.t
+(** [select db id content callback] reads the row [id] in the table of [content]
+ and calls [callback.f] once per field of the content, with the field's named
+ type and its value:
+
+ - the single-column fields ([Text], [Integer], [MonoReference], plus the
+ reserved [parent] column of a subcontent) are read from the content table
+ — their database and code representations coincide;
+ - each multivalued reference field is read from its dedicated table
+ ([content.field]) and yields the sequence of its targets ([int64 Seq.t]).
+
+ The [id] of the row itself is not passed to the callback: it is the [id]
+ argument. In the callback, each [(named, data)] pair can be stored in a
+ value's dictionary to make the field readable as typed data. *)