Module type Fun_sql.Query_sig

Database-agnostic query helpers

val sql : ('a, Stdlib.Format.formatter, unit, string) Stdlib.format4 -> 'a

Convenience for formatting query strings with placeholders. Eg

sql "select name from people where id = %a" placeholder 0
type (-'row, 'r) ret

A decoder of a single row of the resultset from running a query.

val unit : ('row, unit) ret

unit indicates that the query doesn't return any meaningful output.

val ret : ('row -> 'r) -> ('row, 'r Stdlib.Seq.t) ret

ret decode is a custom return type encoding for a resultset into a sequence of values of the type decoded by decode.

decode constructs a value of the custom type if possible, else raises Failure.

Note that the sequence rows of the resultset is unfolded as it is read from the database. It can only be traversed once, with e.g. List.of_seq or Seq.iter. If traversed multiple times, it will raise Failure.

  • raises Invalid_argument

    if any row cannot be decoded.

  • raises Failure

    if an unexpected result code is encountered.

val one : 'a Stdlib.Seq.t -> 'a option
val all : 'a Stdlib.Seq.t -> 'a list