package caqti

  1. Overview
  2. Docs

Parameters

module C : Caqti_connection_sig.Base with type 'a future := 'a Sys.future and type ('a, 'err) stream := ('a, 'err) Sys.Stream.t

Signature

Retrieval Convenience

These are shortcuts for call combined with retrieval functions from Caqti_response_sig.S of the same name.

val exec : ('a, unit, [< `Zero ]) Caqti_request.t -> 'a -> (unit, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

Combining call with Response.exec, this sends a request to the database and checks that no rows are returned.

val exec_with_affected_count : ('a, unit, [< `Zero ]) Caqti_request.t -> 'a -> (int, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

Combining call with Response.exec and Response.affected_count, this sends a request to the database, checks that no rows are returned and returns the number of affected rows.

val find : ('a, 'b, [< `One ]) Caqti_request.t -> 'a -> ('b, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

Combining call with Response.find, this sends a request to the database, checks that a single row is returned, and extracts it.

val find_opt : ('a, 'b, [< `Zero | `One ]) Caqti_request.t -> 'a -> ('b option, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

Combining call with Response.find_opt, this sends a request to the database, checks that at most one row is returned, and extracts it if present.

val fold : ('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t -> ('b -> 'c -> 'c) -> 'a -> 'c -> ('c, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

Combining call with Response.fold, this sends a request to the database and folds over the result rows.

val fold_s : ('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t -> ('b -> 'c -> ('c, 'e) result Sys.future) -> 'a -> 'c -> ('c, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

Combining call with Response.fold_s, this sends a request to the database and folds sequentially over the result rows in a non-blocking manner.

Please be aware of possible deadlocks when using resources from the callback. In particular, if the same connection pool is invoked as the one used to obtain the current connection, it will deadlock if the pool has just run out of connections. An alternative is to collect the rows first e.g. with fold and do the nested queries after exiting.

val iter_s : ('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t -> ('b -> (unit, 'e) result Sys.future) -> 'a -> (unit, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

Combining call with Response.iter_s, this sends a request to the database and iterates sequentially over the result rows in a non-blocking manner. Please see the warning in fold_s about resource usage in the callback.

val collect_list : ('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t -> 'a -> ('b list, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

collect_list request param performs a call on request, extracting the result as a list.

val rev_collect_list : ('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t -> 'a -> ('b list, [> Caqti_error.call_or_retrieve ] as 'e) result Sys.future

rev_collect_list request param performs a call on request, extracting the result as a reversed list. This is more efficient than find_list and fits well with a subsequent List.rev_map, though it may not matter much in practise.

OCaml

Innovation. Community. Security.