Repodb.Driver.Value

repodb · API reference

Low-level database driver interface shared by all Repodb backends.

Most applications use this module indirectly through Repo.Make, Pool.Make, Cqrs.Make, or a concrete driver package such as repodb-sqlite. Driver values are still useful when writing a new backend, decoding custom query results, or using low-level SQL execution for tooling.

A driver exposes a small synchronous contract: connect, execute a statement with typed parameters, query rows, run a transaction, and describe dialect features such as placeholders and RETURNING support. Repodb's higher-level modules build SQL with this contract and translate driver errors into Error.db_error where appropriate.

Rows are represented as column names plus Value.t values. Prefer the typed row helpers when decoding:

type user = { id : int64; email : string; active : bool }

  let decode_user row =
    {
      id = Driver.row_int64 row "id";
      email = Driver.row_text row "email";
      active = Driver.row_bool row "active";
    }

Optional helpers such as row_text_opt return None for SQL NULL and for failed conversions. The _exn helpers are intended for tests and for decoders where missing columns indicate a programming error.

Backend packages implement S; applications usually instantiate a repo with the concrete driver's Driver module:

module Repo = Repodb.Repo.Make (Repodb_sqlite.Driver)
type t = 
  | Null
  | Int of int
  | Int64 of int64
  | Float of float
  | Text of string
  | Blob of string
  | Bool of bool
val null : t
val int : int -> t
val int64 : int64 -> t
val float : float -> t
val text : string -> t
val blob : string -> t
val bool : bool -> t
val of_string : string -> t
val is_null : t -> bool
val to_int : t -> int
val to_int_opt : t -> int option
val to_int64 : t -> int64
val to_int64_opt : t -> int64 option
val to_float : t -> float
val to_float_opt : t -> float option
val to_string : t -> string
val to_string_opt : t -> string option
val to_bool : t -> bool
val to_bool_opt : t -> bool option