package caqti-lwt
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=b8ea432820154ec095132c4f7b244b06cd8553e0b2035185b844d9c4f30af8bb
sha512=b7e3ad8e6a9b587db2d517e15cd42df2945148f9223b2fa6f4bc2bcdd2709d53549cca4b65e54511d22466e4c9aa7f0b9c17305a07505519d8bf81d95de629b8
doc/caqti-lwt.unix/Caqti_lwt_unix/index.html
Module Caqti_lwt_unix
Source
Connecting on Unix-like platforms using Lwt
This module contains functions for connecting to databases using the lwt.unix library, providing support for all drivers.
See also Caqti_lwt
for basic Lwt support.
include Caqti_connect_sig.S
with type 'a fiber := 'a Lwt.t
and type ('a, 'e) stream := ('a, 'e) Caqti_lwt.Stream.t
and type ('a, 'e) pool := ('a, 'e) Pool.t
and type connection := Caqti_lwt.connection
and type 'a with_switch := ?sw:Caqti_lwt.Switch.t -> 'a
and type 'a with_stdenv := 'a
val connect :
?subst:(Caqti_template.Dialect.t -> Caqti_template.Query.subst) ->
?env:(Caqti_driver_info.t -> string -> Caqti_query.t) ->
?config:Caqti_connect_config.t ->
?tweaks_version:(int * int) ->
?sw:Caqti_lwt.Switch.t ->
Uri.t ->
(Caqti_lwt.connection, [> Caqti_error.load_or_connect ]) result Lwt.t
connect uri
locates and loads a driver which can handle uri
, passes uri
to the driver, which establish a connection and returns a first-class module implementing Caqti_connection_sig.S
.
connect uri
connects to the database at uri
and returns a first class module implementing Caqti_connection_sig.S
for the given database system. In case of preemptive threading, the connection must only be used from the thread where it was created.
The correct driver for the database system is inferred from the schema of uri
; see the respective drivers for the supported schemas and related URI syntax. A driver can either be linked in to the application or, if supported, dynamically linked using the caqti-dynload
package.
val with_connection :
?subst:(Caqti_template.Dialect.t -> Caqti_template.Query.subst) ->
?env:(Caqti_driver_info.t -> string -> Caqti_query.t) ->
?config:Caqti_connect_config.t ->
?tweaks_version:(int * int) ->
Uri.t ->
(Caqti_lwt.connection ->
('a, [> Caqti_error.load_or_connect ] as 'e) result Lwt.t) ->
('a, 'e) result Lwt.t
val connect_pool :
?pool_config:Caqti_pool_config.t ->
?post_connect:(Caqti_lwt.connection -> (unit, 'connect_error) result Lwt.t) ->
?subst:(Caqti_template.Dialect.t -> Caqti_template.Query.subst) ->
?env:(Caqti_driver_info.t -> string -> Caqti_query.t) ->
?config:Caqti_connect_config.t ->
?tweaks_version:(int * int) ->
?sw:Caqti_lwt.Switch.t ->
Uri.t ->
((Caqti_lwt.connection, [> Caqti_error.connect ] as 'connect_error) Pool.t,
[> Caqti_error.load ])
result
connect_pool uri
is a pool of database connections constructed by connect uri
.
Do not use pooling for connections to volatile resources like sqlite3::memory:
and beware of temporary tables or other objects which may not be shared across connections to the same URI.
If you use preemptive threading, note that the connection pool must only be used from the thread where it was created. Use thread local storage to create a separate pool per thread if necessary.