package caqti

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Parameters

module Sys : System_sig.S
module _ : Caqti_connection_sig.Base with type 'a fiber := 'a Sys.Fiber.t and type ('a, 'err) stream := ('a, 'err) Sys.Stream.t

Signature

Retrieval Convenience

Each of these shortcuts combine call with the correspondingly named retrieval function from Caqti_response_sig.S.

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

exec req x performs req with parameters x and checks that no rows are returned. See also Caqti_response_sig.S.exec.

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

exec_with_affected_count req x performs req with parameters x, checks that no rows are returned, and returns the number of affected rows.

See also Caqti_response_sig.S.exec and Caqti_response_sig.S.affected_count.

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

find req x performs req with parameters x, checks that a single row is retured, and returns it.

See also Caqti_response_sig.S.find.

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

find_opt req x performs req with parameters x and returns either None if no rows are returned or Some y if a single now y is returned and fails otherwise.

See also Caqti_response_sig.S.find_opt.

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

fold req f x acc performs req with parameters x and passes acc through the composition of f y across the result rows y in the order of retrieval.

See also Caqti_response_sig.S.fold.

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

fold_s req f x acc performs req with parameters x and passes acc through the monadic composition of f y across the returned rows y in the order of retrieval.

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.

See also Caqti_response_sig.S.fold_s.

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

iter_s req f x performs req with parameters x and sequences calls to f y for each result row y in the order of retrieval.

Please see the warning in fold_s about resource usage in the callback.

See also Caqti_response_sig.S.iter_s.

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

collect_list request x performs a req with parameters x and returns a list of rows in order of retrieval. The accumulation is tail recursive but slightly less efficient than rev_collect_list.

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

rev_collect_list request x performs request with parameters x and returns a list of rows in the reverse order of retrieval. The accumulation is tail recursive and slighly more efficient than collect_list.

Transactions

val with_transaction : (unit -> ('a, 'e) Stdlib.result Sys.Fiber.t) -> ('a, [> Caqti_error.transact ] as 'e) Stdlib.result Sys.Fiber.t

with_transaction f wraps f in a transaction which is committed iff f returns Ok _.

OCaml

Innovation. Community. Security.