Module Rel.Row

Row definitions.

A row is defined by a cartesian product of columns definitions and a function for injecting them into the OCaml type that represents them.

Rows

type ('r, 'a) prod

The type for constructing a cartesian product whose final result is represented by OCaml values of type 'r.

type 'r t = ('r, 'r) prod

The type for a row represented by OCaml values of type 'r.

val unit : 'a -> ('r, 'a) prod

unit f is a (virtual) unit column with constructor f to be saturated by prod.

val prod : ('r, 'a -> 'b) prod -> ('r, 'a) Col.t -> ('r, 'b) prod

prod r c is the product of columns r with c.

val (*) : ('r, 'a -> 'b) prod -> ('r, 'a) Col.t -> ('r, 'b) prod

* is Row.prod.

val cat : ('r, 'a -> 'b) prod -> proj:('r -> 'a) -> 'a t -> ('r, 'b) prod

cat r ~proj row is the product of columns r with the columns of row, proj is used to project row values from the result of r. Warning this may be removed in the future.

val empty : unit t

empty is the empty product unit (). This can be used as a specification for the result of side effecting SQL statements like UPDATE.

Quick row specification

These functions contructs rows with columns that have no parameters and a default projection of Col.no_proj. They can be used to quickly devise rows for query results.

Warning. Since by default these column constructors lack projection Row.value_pp cannot be used on them. Those created with tuple constructors do however (re)define projection.

Column definitions

val col : ?proj:('r -> 'a) -> string -> 'a Type.t -> ('r, 'a) Col.t

col n t is column named n of type t.

val bool : ?proj:('r -> bool) -> string -> ('r, bool) Col.t

bool n is a boolean column named n.

val int : ?proj:('r -> int) -> string -> ('r, int) Col.t

int n is an integer column named n.

val int64 : ?proj:('r -> int64) -> string -> ('r, int64) Col.t

int64 n is an 64-bit integer column named n.

val float : ?proj:('r -> float) -> string -> ('r, float) Col.t

float n is a float column named n.

val text : ?proj:('r -> string) -> string -> ('r, string) Col.t

text n is a text column named n.

val blob : ?proj:('r -> string) -> string -> ('r, string) Col.t

blob n is a blob column named n.

val option : ?proj:('r -> 'a option) -> 'a Type.t -> string -> ('r, 'a option) Col.t

option t n is a nullable t column named n.

Tuple constructors

val t1 : (_, 'a) Col.t -> 'a t

t1 construct and deconstructs values with the given column. This redefines the projection to the identity.

val t2 : (_, 'a) Col.t -> (_, 'b) Col.t -> ('a * 'b) t

t2 constructs and deconstructs pairs with the given column types. This redefine the projections of the columns.

val t3 : (_, 'a) Col.t -> (_, 'b) Col.t -> (_, 'c) Col.t -> ('a * 'b * 'c) t

t3 constructs and deconstructs triplets with the given column types. This redefine the projections of the columns.

val t4 : (_, 'a) Col.t -> (_, 'b) Col.t -> (_, 'c) Col.t -> (_, 'd) Col.t -> ('a * 'b * 'c * 'd) t

t4 constructs and deconstructs quadruplets with the given column types. This redefine the projections of the columns.

val t5 : (_, 'a) Col.t -> (_, 'b) Col.t -> (_, 'c) Col.t -> (_, 'd) Col.t -> (_, 'e) Col.t -> ('a * 'b * 'c * 'd * 'e) t

t5 constructs and deconstructs quintuplets with the given column types. This redefine the projections of the columns.

val t6 : (_, 'a) Col.t -> (_, 'b) Col.t -> (_, 'c) Col.t -> (_, 'd) Col.t -> (_, 'e) Col.t -> (_, 'f) Col.t -> ('a * 'b * 'c * 'd * 'e * 'f) t

t6 constructs and deconstructs sextuplets with the given column types. This redefine the projections of the columns.

Traversal

val fold : ('a -> 'r Col.def -> 'a) -> 'a -> ('r, 'b) prod -> 'a

fold f acc r folds over the columns of f from right-to-left.

Columns

val cols : ('r, 'a) prod -> 'r Col.def list

cols r are the columns in row r, from left-to-right, untyped.

val col_count : ('r, 'a) prod -> int

col_count r is the number of columns in row r.

Formatters

val pp_header : 'r t fmt

pp_header formats the column names of the row.

val value_pp : 'r t -> 'r fmt

value_pp r formats values of r.

val value_pp_list : ?header:bool -> 'r t -> 'r list fmt

value_pp_list formats list of values of r, one per line. If header is true, starts by formatting the headers of r.

Low-level representation

module Repr : sig ... end

Low-level representation (unstable).