summaryrefslogtreecommitdiff
path: root/lib/model/data.ml
blob: 2d00c4e5534de2c58ee10f065ea338a47374305d (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
(** The data carried by a field of a value.

    [None] tells the field is empty (or left as is, on update), [V] carries a
    single value together with the type of its field, and [Seq] carries a
    sequence of references for a multivalued field.

    The type is parameterized over the type of the data held (['a]: the DB
    representation of the field, e.g. [string option] or [int64 option]) and
    over ['t], the target of the field for references — a reference is held as
    an [int64] (the id of the target row), while ['t] records what it points to.
    The field type {!Types.t} stays in the model package; only the data itself
    lives here. *)
type ('ocaml, 't) data =
  | None
  | V : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data

let none : ('ocaml, 't) data = None

let v : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data =
 fun (typ, value) -> V (typ, value)

type 't any = Any : ('ocaml, 't) data -> 't any [@@unboxed]

let any : ('ocaml, 't) data -> 't any = fun data -> Any data