Library
Module
Module type
Parameter
Class
Class type
The connection API specialized for the current concurrency library.
include Caqti_connection_sig.Base with type 'a future := 'a Async.Deferred.t
module Response :
Caqti_response_sig.S with type 'a future := 'a Async.Deferred.t
val call :
f:(('b, 'm) Response.t -> ('c, 'e) result Async.Deferred.t) ->
('a, 'b, 'm) Caqti_request.t ->
'a ->
('c, [> Caqti_error.call ] as 'e) result Async.Deferred.t
call ~f request params
performs request
with parameters params
invoking f
to process the result.
val start : unit -> (unit, [> Caqti_error.transact ]) result Async.Deferred.t
Starts a transaction if supported by the underlying database, otherwise does nothing.
val commit : unit -> (unit, [> Caqti_error.transact ]) result Async.Deferred.t
Commits the current transaction if supported by the underlying database, otherwise does nothing.
val rollback :
unit ->
(unit, [> Caqti_error.transact ]) result Async.Deferred.t
Rolls back a transaction if supported by the underlying database, otherwise does nothing.
val disconnect : unit -> unit Async.Deferred.t
Calling disconnect ()
closes the connection to the database and frees up related resources.
val validate : unit -> bool Async.Deferred.t
For internal use by Caqti_pool
. Tries to ensure the validity of the connection and must return false
if unsuccessful.
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.
val driver_info : Caqti_driver_info.t
Information about the driver providing this connection module.
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 Async.Deferred.t
Combines call
with Response.exec
.
val find :
('a, 'b, [< `One ]) Caqti_request.t ->
'a ->
('b, [> Caqti_error.call_or_retrieve ] as 'e) result Async.Deferred.t
Combines call
with Response.find
.
val find_opt :
('a, 'b, [< `Zero | `One ]) Caqti_request.t ->
'a ->
('b option, [> Caqti_error.call_or_retrieve ] as 'e) result Async.Deferred.t
Combines call
with Response.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) result Async.Deferred.t
Combines call
with Response.fold
.
val fold_s :
('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t ->
('b -> 'c -> ('c, 'e) result Async.Deferred.t) ->
'a ->
'c ->
('c, [> Caqti_error.call_or_retrieve ] as 'e) result Async.Deferred.t
Combines call
with Response.fold_s
.
val iter_s :
('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t ->
('b -> (unit, 'e) result Async.Deferred.t) ->
'a ->
(unit, [> Caqti_error.call_or_retrieve ] as 'e) result Async.Deferred.t
Combines call
with Response.iter_s
.
val collect_list :
('a, 'b, [< `Zero | `One | `Many ]) Caqti_request.t ->
'a ->
('b list, [> Caqti_error.call_or_retrieve ] as 'e) result Async.Deferred.t
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 Async.Deferred.t
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.