package caqti
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=e1f580848faf3a54f23174067f2c75f77f6a2fe50ca8bc923428d0e1841192c5
sha512=7a11edfcfbbe4855347b066e222cf6bf46d1afedcd4978661b9a2b3931921faa1768a6bc24031fd3afa84537fe2adc8b139399deb77120461bee8fb394d68e82
doc/caqti.blocking/Caqti_blocking/module-type-CONNECTION/index.html
Module type Caqti_blocking.CONNECTIONSource
The connection API specialized for the current concurrency library.
val driver_info : Caqti_driver_info.tInformation about the driver providing this connection module.
val driver_connection : Caqti_connection_sig.driver_connection optionThe underlying connection object of the driver if available. The open variant constructor is defined in the driver library. This is currently only implemented for caqti-driver-sqlite3 for the purpose of defining custom functions.
include Caqti_connection_sig.Base
with type 'a future := 'a future
with type ('a, 'err) stream := ('a, 'err) Stream.t
Query
val call :
f:(('b, 'm) Response.t -> ('c, 'e) result future) ->
('a, 'b, 'm) Caqti_request.t ->
'a ->
('c, [> Caqti_error.call ] as 'e) result futurecall ~f request params performs request with parameters params invoking f to process the result. The argument of f is only valid during the call to f, and must not be returned or operated on by other threads.
val set_statement_timeout :
float option ->
(unit, [> Caqti_error.call ]) result futureSet or clear the timeout after which a running SQL statement will be terminated if supported by the driver. This is currently supported for MariaDB (using max_statement_time) and PostgreSQL (using statement_timeout) and has no effect for SQLite3.
Transactions
val start : unit -> (unit, [> Caqti_error.transact ]) result futureStarts a transaction if supported by the underlying database, otherwise does nothing.
val commit : unit -> (unit, [> Caqti_error.transact ]) result futureCommits the current transaction if supported by the underlying database, otherwise does nothing.
val rollback : unit -> (unit, [> Caqti_error.transact ]) result futureRolls back a transaction if supported by the underlying database, otherwise does nothing.
Disconnection and Reuse
val deallocate :
('a, 'b, 'm) Caqti_request.t ->
(unit, [> Caqti_error.call ]) result futuredeallocate req deallocates the prepared query for req if it was allocated. The request must not be oneshot.
val disconnect : unit -> unit futureCalling disconnect () closes the connection to the database and frees up related resources.
val validate : unit -> bool futureFor 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.
include Caqti_connection_sig.Convenience with type 'a future := 'a future
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 futureCombining 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 futureCombining 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 futureCombining 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 futureCombining 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 futureCombining 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 future) ->
'a ->
'c ->
('c, [> Caqti_error.call_or_retrieve ] as 'e) result futureCombining 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 future) ->
'a ->
(unit, [> Caqti_error.call_or_retrieve ] as 'e) result futureCombining 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 futurecollect_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 futurerev_collect_list request param performs a call on request, extracting the result as a reversed list. This is more efficient than collect_list and fits well with a subsequent List.rev_map, though it may not matter much in practise.
Transactions
val with_transaction :
(unit -> ('a, 'e) result future) ->
('a, [> Caqti_error.transact ] as 'e) result futurewith_transaction f wraps f in a transaction which is committed iff f returns Ok _.
include Caqti_connection_sig.Populate
with type 'a future := 'a future
and type ('a, 'err) stream := ('a, 'err) Stream.t
Insertion
val populate :
table:string ->
columns:string list ->
'a Caqti_type.t ->
('a, 'err) Stream.t ->
(unit, [> Caqti_error.call_or_retrieve | `Congested of 'err ]) result futurepopulate table columns row_type seq inputs the contents of seq into the database in whatever manner is most efficient as decided by the driver.