summaryrefslogtreecommitdiff
path: root/lib/query/select.mli
blob: 68e4d00b3cf7082e85756b3d38a672d7ab3693b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(** Read a row of a content table from the database *)

type callback = {
  f :
    'db 'ocaml.
    ('db, 'ocaml, Model.target) Model.Types.t Model.Types.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. *)

val select_list :
  Caqti_lwt.connection -> Int64.t -> Model.list -> callback -> unit Lwt.t
(** Same as {!select}, for a row of the dedicated table of a static list. Lists
    have no [parent] column; their multivalued reference fields are read from
    their dedicated tables ([list.field]), like for contents. *)