package caqti

  1. Overview
  2. Docs
Unified interface to relational database libraries

Install

dune-project
 Dependency

Authors

Maintainers

Sources

caqti-v3.0.0.tbz
sha256=3ceea06ba0e8e8bcab0386b5817b68cb30fce457eaa25ada0182891d66f6a0b9
sha512=e01f546a45b04cafd5fa262e9228e5a1aabd5e0942059c073a4181c928450baf3d990cc59ffb1a33dff445b46a0e218224a23dca96e8d24cdd0ab793d08e4538

doc/caqti/Caqti/Connection/module-type-Convenience/index.html

Module type Connection.ConvenienceSource

type +'a fiber

Retrieval Convenience

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

val exec : ('a, unit, [< `Zero ]) Template.Request.t -> 'a -> (unit, [> Error.call_or_retrieve ]) result fiber

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

val exec_with_affected_count : ('a, unit, [< `Zero ]) Template.Request.t -> 'a -> (int, [> Error.call_or_retrieve | `Unsupported ]) result fiber

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.S.exec and Caqti.Response.S.affected_count.

val find : ('a, 'b, [< `One ]) Template.Request.t -> 'a -> ('b, [> Error.call_or_retrieve ]) result fiber

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

See also Caqti.Response.S.find.

val find_opt : ('a, 'b, [< `Zero | `One ]) Template.Request.t -> 'a -> ('b option, [> Error.call_or_retrieve ]) result fiber

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.S.find_opt.

val fold : ('a, 'b, [< `Zero | `One | `Many ]) Template.Request.t -> ('b -> 'c -> 'c) -> 'a -> 'c -> ('c, [> Error.call_or_retrieve ]) result fiber

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.S.fold.

val fold_s : ('a, 'b, [< `Zero | `One | `Many ]) Template.Request.t -> ('b -> 'c -> ('c, 'e) result fiber) -> 'a -> 'c -> ('c, [> Error.call_or_retrieve ] as 'e) result fiber

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.S.fold_s.

val iter_s : ('a, 'b, [< `Zero | `One | `Many ]) Template.Request.t -> ('b -> (unit, 'e) result fiber) -> 'a -> (unit, [> Error.call_or_retrieve ] as 'e) result fiber

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.S.iter_s.

val collect_list : ('a, 'b, [< `Zero | `One | `Many ]) Template.Request.t -> 'a -> ('b list, [> Error.call_or_retrieve ]) result fiber

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 ]) Template.Request.t -> 'a -> ('b list, [> Error.call_or_retrieve ]) result fiber

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) result fiber) -> ('a, [> Error.transact ] as 'e) result fiber

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