Library
Module
Module type
Parameter
Class
Class type
Provides an SQL E-DSL for writing well-typed SQL expressions.
type 'a t = 'a Expr.t
'a t
represents an SQL expression that produces a value corresponding to the type 'a
.
type 'a expr_list = 'a Expr.expr_list =
Represents a heterogeneous sequence of SQL expressions.
Note Provided you have opened the Expr module, you can use List syntax to construct such lists:
open Petrol.Sqlite3
Expr.[i 1; bl false]
(* - : (int * (bool * ())) Expr.expr_list *)
type wrapped_assign = Expr.wrapped_assign
An opaque wrapper that represents an assignment of a value to a particular field in a table.
The following functions define constant value expressions.
Note For each type, there are two flavours of constant expression: variable and static.
The key difference between the two is in terms of how they are represented in the final SQL query - in particular, variable constant expressions are encoded as holes (?) in the query, to which a constant value is supplied, whereas static constant expressions are encoded directly in the query string.
As Petrol functions cache the construction of SQL queries by their final string representation, you should prefer the dynamic form if you expect the constant value to change frequently - for example, if it is a constant value that you are receiving from elsewhere. Use the static form if you know that the value doesn't change and will always be the same.
val i : int -> int t
i v
returns an expression that evaluates to the integer value v
.
val f : float -> float t
f v
returns an expression that evaluates to the real value v
.
val s : string -> string t
s v
returns an expression that evaluates to the string value v
.
val bl : bool -> bool t
bl v
returns an expression that evaluates to the bool value v
.
vl ~ty value
returns an expression that evaluates to the value value
with type ty
.
val i_stat : int -> int t
i_stat v
returns a static expression that evaluates to the integer value v
.
val f_stat : float -> float t
f_stat v
returns a static expression that evaluates to the real value v
.
val s_stat : string -> string t
s_stat v
returns a static expression that evaluates to the string value v
.
val true_ : bool t
true_
represents the SQL constant TRUE
.
val false_ : bool t
false_
represents the SQL constant FALSE
.
vl_stat ~ty value
returns a static expression that evaluates to the value value
with type ty
.
as_ exp ~name
returns a tuple (exp',exp'_ref)
where exp'
is the SQL expression exp AS name
that names exp
as name
, and exp'_ref
is simply name
.
nullable e
encodes the fact that the expression e
may return NULL
.
is_not_null e
constructs an SQL expression that is TRUE
iff the expression e
is not NULL
and FALSE
otherwise.
is_null e
constructs an SQL expression that is TRUE
iff the expression e
is NULL
and FALSE
otherwise.
coerce expr ty
coerces expression expr
to the type ty
. This coercion is not checked, so make sure you know what you're doing or it could fail at runtime.
val (:=) : 'a t -> 'a t -> wrapped_assign
v := expr
returns an SQL expression that can be used with an update or insert clause to change the values in the database.
val unset : 'a t -> wrapped_assign
unset v
returns an SQL expression that can be used with an update query to set a field to NULL in the database.
val ceil_gen : ty:'a Type.Numeric.t -> 'a t -> 'a t
val floor_gen : ty:'a Type.Numeric.t -> 'a t -> 'a t
val round_gen : ty:'a Type.Numeric.t -> 'a t -> 'a t
val trunc_gen : ty:'a Type.Numeric.t -> 'a t -> 'a t
val pi : float t
val power_gen : ty:'a Type.Numeric.t -> 'a t -> 'a t -> 'a t
val factorial_gen : ty:'a Type.Numeric.integral -> 'a t -> 'a t
val gcd_gen : ty:'a Type.Numeric.integral -> 'a t -> 'a t -> 'a t
val lcm_gen : ty:'a Type.Numeric.integral -> 'a t -> 'a t -> 'a t
val abs_gen : 'a Type.Numeric.t -> 'a t -> 'a t
val count_star : int t
val max_gen : ?distinct:bool -> 'a Type.Numeric.t -> 'a t -> 'a t
val min_gen : ?distinct:bool -> 'a Type.Numeric.t -> 'a t -> 'a t
val sum_gen : ?distinct:bool -> 'a Type.Numeric.t -> 'a t -> 'a t
val greatest_gen : ty:'a Type.Numeric.t -> 'a t list -> 'a t
val least_gen : ty:'a Type.Numeric.t -> 'a t list -> 'a t
val random : float t