Something went wrong. Try again.
SQL frontend over the catalog engine
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
(** JSONB codecs: {e finally tagged} combinators over the element types. [t] is a GADT; interpreters walk it to read and write JSONB bytes, and to cross to and from {!Jsonb_value.t}. Reading takes the bytes in place: a codec reads the element it names and nothing else. *)
type 'a t(** The type for codecs between JSONB elements and OCaml values of type ['a]. *)
val null : 'a -> 'a t(** [null v] reads a NULL as [v] and writes NULL. *)
val bool : bool t(** [bool] reads TRUE and FALSE. *)
val int : string t(** [int] reads an INT or an INT5 as its text, and writes INT5 for hexadecimal text, INT otherwise. *)
val float : string t(** [float] reads a FLOAT or a FLOAT5 as its text, and writes FLOAT. *)
val text : string t(** [text] reads any text element as its string, the escapes of a TEXTJ or a TEXT5 read, and writes TEXTRAW. *)
val element : string t(** [element] reads an element as its own JSONB bytes, header included, and writes such bytes as they are. *)
val ignore : unit t(** [ignore] reads any element, and has no encoder. *)
val array : 'a t -> 'a list t(** [array c] reads an ARRAY, each element with [c]. *)
val members : 'a t -> (string * 'a) list t(** [members c] reads an OBJECT as its labels, read as {!text} reads them, and its values read with [c], in order. It writes each label TEXTRAW. *)
val map : ?kind:string -> ?dec:('a -> 'b) -> ?enc:('b -> 'a) -> 'a t -> 'b t(** [map ~kind ~dec ~enc c] reads with [c] then [dec], and writes [enc] then with [c]. A missing [dec] or [enc] fails, naming [kind]. *)
val any : ?kind:string -> ?null:'a t -> ?bool:'a t -> ?int:'a t -> ?float:'a t -> ?text:'a t -> ?array:'a t -> ?object':'a t -> ?enc:('a -> 'a t) -> unit -> 'a t(** [any ()] reads each element type with the codec given for it, [int] for both INT and INT5, [float] for both reals and [text] for the four text types, and writes with the codec [enc] picks. *)
val json : Json.t t(** [json] reads an element as nox-json's value, a number as its RFC 8259 text, an INT5 or a FLOAT5 as json() writes it, kept as the number's lexeme, and a string with its escapes read. It writes such a value, a number as the lexeme it was read from or as sqlite3 writes an integer or a real, NaN as NULL, and a string TEXTRAW. *)
(** The identity codec. *)module Value : sig val t : Jsonb_value.t t (** [t] reads an element as its {!Jsonb_value.t}, and writes one. *)end
(**/**)
val dec_at : 'a t -> Jsonb_core.t -> int -> 'a(** [dec_at c t i] reads the element at [i] of [t] with [c]. *)
val enc_into : 'a t -> 'a -> Jsonb_core.t -> unit(** [enc_into c v t] adds [v]'s element to [t]. *)
val to_bytes : 'a t -> 'a -> string(** [to_bytes c v] is [v]'s element. *)
val decode : 'a t -> Jsonb_value.t -> 'a(** [decode c v] reads the value [v] with [c]. *)
val encode : 'a t -> 'a -> Jsonb_value.t(** [encode c v] is [v] as a value. *)
(**/**)