Module Rel_sql.Stmt

Typed SQL statements.

See the SQL statement typing howto for a short introduction.


type arg =
  1. | Arg : 'a Rel.Type.t * 'a -> arg

The type for SQL statement arguments (parameters).

val pp_arg : Stdlib.Format.formatter -> arg -> unit

pp_arg formats an argument with Rel.Type.value_pp.


type 'r t

The type for a closed (all arguments are bound) SQL statement returning rows of type 'r. Note that this must be a single statement.

val v : string -> rev_args:arg list -> result:'r Rel.Row.t -> 'r t

v sql rev_args result is a closed statement with srouce sql, revered list of arguments (parameters) rev_args and yielding rows of type result.

val src : 'r t -> string

src st is the source SQL statement of st.

val result : 'r t -> 'r Rel.Row.t

result s is the result of s.

val rev_args : 'r t -> arg list

rev_args st is the reversed list of arguments of the statement.

val pp_src : Stdlib.Format.formatter -> 'r t -> unit

pp_src formats the statement's source.

val pp : Stdlib.Format.formatter -> 'r t -> unit

pp ppf st formats the statement's source and its arguments.

Binding functions

type 'a func

The type for open SQL statements with argument binding function of type 'a.

val func : string -> 'a func -> 'a

func sql f is the binding function of f used on the source SQL statement sql.

val ret : 'r Rel.Row.t -> 'r t func

ret st row is an open SQL statement st returning values of type row.

val ret_rev : 'r Rel.Row.t -> 'r t func
val arg : 'a Rel.Type.t -> 'b func -> ('a -> 'b) func

arg t f binds a new variable of type t to f.

val (@->) : 'a Rel.Type.t -> 'b func -> ('a -> 'b) func

t @-> f is arg t f.

val unit : unit t func

unit is ret Rel.Row.empty.

The following constants get redefined here to allow consise specification with the Sql.Stmt.() notation.

val bool : bool Rel.Type.t

bool is Rel.Type.Bool.

val int : int Rel.Type.t

int is Rel.Type.Int.

val int64 : int64 Rel.Type.t

int64 is Rel.Type.Int64.

val float : float Rel.Type.t

float is Rel.Type.Float.

val text : string Rel.Type.t

text is Rel.Type.Text.

val blob : string Rel.Type.t

blob is Rel.Type.Blob.

val option : 'a Rel.Type.t -> 'a option Rel.Type.t

option t is Rel.Type.Option t.

Binding projections

See the this section of the SQL statement typing howto.

val nop : 'b func -> ('a -> 'b) func

nop f adds an unused argument to f.

val proj : ('r -> 'a) -> 'a Rel.Type.t -> ('r -> 'b) func -> ('r -> 'b) func

proj p t binds the projection p of a value of type t.

val col : ('r, 'a) Rel.Col.t -> ('r -> 'b) func -> ('r -> 'b) func

col c f binds the projection on column c of a row of type 'r