package caqti

  1. Overview
  2. Docs

Interface for constructing query parameters.

Interface for extracting result tuples.

type 'a io = 'a System.io

The IO monad for which the module is specialized.

val uri : Uri.t

The URI used to connect to the database.

val driver_info : Caqti_driver_info.t

Information about the database driver which provides this connection.

val disconnect : unit -> unit io

Calling disconnect () closes the connection to the database and frees up related resources.

val validate : unit -> bool io

For internal use by Caqti_pool. Tries to ensure the validity of the connection and must return false if unsuccessful.

val check : (bool -> unit) -> unit

For internal use by Caqti_pool. Called after a connection has been used. check f must call f () exactly once with an argument indicating whether to keep the connection in the pool or discard it.

Returns a description of parameters and returned tuples. What is returned may be limited by what the underlying library supports. The number of paratemers and tuple components should be correct, but the types may be `Unknown.

Querying

val exec : Caqti1_query.query -> Param.t array -> unit io

exec q params executes a query q(params) which is not expected to return anything.

val find : Caqti1_query.query -> (Tuple.t -> 'a) -> Param.t array -> 'a io

find_e q params executes q(params) which is expected to return exactly one tuple.

val find_opt : Caqti1_query.query -> (Tuple.t -> 'a) -> Param.t array -> 'a option io

find q params executes a query q(params) which is expected to return at most one tuple.

val fold : Caqti1_query.query -> (Tuple.t -> 'a -> 'a) -> Param.t array -> 'a -> 'a io

fold q f params acc executes q(params), composes f over the resulting tuples in order, and applies the composition to acc.

val fold_s : Caqti1_query.query -> (Tuple.t -> 'a -> 'a io) -> Param.t array -> 'a -> 'a io

fold_s q f params acc executes q(params), forms a threaded composition of f over the resulting tuples, and applies the composition to acc.

val iter_p : Caqti1_query.query -> (Tuple.t -> unit io) -> Param.t array -> unit io

fold_p q f params executes q(params) and calls f t in the thread monad in parallel for each resulting tuple t. A certain backend may not implement parallel execution, in which case this is the same as iter_s.

val iter_s : Caqti1_query.query -> (Tuple.t -> unit io) -> Param.t array -> unit io

fold_s q f params executes q(params) and calls f t sequentially in the thread monad for each resulting tuple t in order.

Transactions

val start : unit -> unit io

Starts a transaction if supported by the underlying database, otherwise does nothing.

val commit : unit -> unit io

Commits the current transaction if supported by the underlying database, otherwise does nothing.

val rollback : unit -> unit io

Rolls back a transaction if supported by the underlying database, otherwise does nothing.