A pure OCaml PostgreSQL client library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc Add more files topkg wants May 31, 2018
pgx Use a tail-recursive List.map implementation Nov 14, 2018
pgx_test/src Go full Dune Oct 26, 2018
pgx_unix Work around getlogin failing for lwt Feb 7, 2019
.editorconfig Add .editorconfig Dec 21, 2017
README.md Add a missing ` to the README Jan 22, 2019
pgx_async.descr Remove prefixes from .descr files Jun 1, 2018
pgx_async.opam Dune Oct 26, 2018
pgx_unix.descr Remove prefixes from .descr files Jun 1, 2018


CircleCI Coverage Status

PGX is a pure-OCaml PostgreSQL client library, supporting Async, LWT, or synchronous operations.

API documentation

This is an early release. The API is likely to change significantly before the 1.0 release.

This library focuses on correctness and safety, with features like:

  • It is nearly impossible to try to execute a prepared statement that hasn't been prepared.
  • Trying to run multiple queries at the same time will work properly (although there's no performance benefit, since we currently don't send queries in parallel).
  • Lots of automated tests.
  • Pgx.Value for parameters and returned data, encouraging people to use the built-in converters instead of trying to handle everything as a string.
  • Async and LWT support are built in, no need to write your own IO module.

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 pin add pgx https://github.com/arenadotio/pgx.git


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 ...";