Page
Library
Module
Module type
Parameter
Class
Class type
Source
PGX is a pure-OCaml PostgreSQL client library, supporting Async, LWT, or synchronous operations.
This library focuses on correctness and safety, with features like:
Pgx.Value
for parameters and returned data, encouraging people to use the built-in converters instead of trying to handle everything as a string.We also provide a relatively high-level interface, like Pgx_async.execute_pipe
, which prepares a statement, executes it with the given parameters, returns an Async.Pipe.Reader.t
(so you can stream results), and unprepares the statement when the query is finished.
Significant portions of the code come from PG'Ocaml.
opam install pgx_async # or pgx_lwt_unix or pgx_unix or pgx_lwt_mirage
See pgx_async/bin/pgx_async_example.ml for a complete example of the high-level functional interface. To translate the example to Lwt, replace Pgx_async
with Pgx_lwt
and >>|
with >|=
. To translate it to synchronous IO / standard-library-only, use Pgx_unix
and replace both >>|
and >>=
with |>
, or just replace >>| fun () ->
with ;
.
I.e. in Pgx_unix
, you can replace:
Pgx_async.execute ~params "INSERT INTO ..."
>>| fun () ->
... with:
Pgx_unix.execute ~params "INSERT INTO ...";