Sqlite.Db
Caqti convenience functions wrapped in the Tezos error monad. See Caqti_connection_sig.Convenience
.
Type representing a direct connection to the database with tracing capabilities. This is used internally by the connection handling functions.
val exec :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, unit, [< `Zero ]) Request.t ->
'a ->
unit Tezos_error_monad.Error_monad.tzresult Lwt.t
exec req x
performs req
with parameters x
and checks that no rows are returned.
val find :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, 'b, [< `One ]) Request.t ->
'a ->
'b Tezos_error_monad.Error_monad.tzresult Lwt.t
find req x
performs req
with parameters x
, checks that a single row is retured, and returns it.
val find_opt :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, 'b, [< `One | `Zero ]) Request.t ->
'a ->
'b option Tezos_error_monad.Error_monad.tzresult Lwt.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.
val collect_list :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, 'b, [< `Many | `One | `Zero ]) Request.t ->
'a ->
'b list Tezos_error_monad.Error_monad.tzresult Lwt.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 :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, 'b, [< `Many | `One | `Zero ]) Request.t ->
'a ->
'b list Tezos_error_monad.Error_monad.tzresult Lwt.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
.
val fold :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, 'b, [< `Many | `One | `Zero ]) Request.t ->
('b -> 'c -> 'c) ->
'a ->
'c ->
'c Tezos_error_monad.Error_monad.tzresult Lwt.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.
val fold_s :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, 'b, [< `Many | `One | `Zero ]) Request.t ->
('b -> 'c -> ('c, Caqti_error.t) Stdlib.result Lwt.t) ->
'a ->
'c ->
'c Tezos_error_monad.Error_monad.tzresult Lwt.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.
val iter_s :
?scope:Opentelemetry.Scope.t ->
conn ->
('a, 'b, [< `Many | `One | `Zero ]) Request.t ->
('b -> (unit, Caqti_error.t) Stdlib.result Lwt.t) ->
'a ->
unit Tezos_error_monad.Error_monad.tzresult Lwt.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.