Module Sql.Stmt

Typed SQL statements.

This module provides a low-level mechanism to type SQL statements arguments (parameters) and bind their arguments to value via an OCaml binding function.

See the SQL statement typing howto for a short introduction.


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

The type for SQL statement arguments (parameters).


type 'r t

The type for a closed (all arguments are bound) SQL statements returning rows of type 'r.

val src : 'r t -> string

src st is the source SQL statement of st.

val result : 'r t -> 'r 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.

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 Row.t -> 'r t func

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

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

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

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

t @-> f is arg t f.

val unit : unit t func

unit is ret Row.empty.

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

val bool : bool Type.t

bool is Type.Bool.

val int : int Type.t

int is Type.Int.

val int64 : int64 Type.t

int64 is Type.Int64.

val float : float Type.t

float is Type.Float.

val text : string Type.t

text is Type.Text.

val blob : string Type.t

blob is Type.Blob.

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

option t is !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 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) Col.t -> ('r -> 'b) func -> ('r -> 'b) func

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